@@ -430,7 +430,11 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
430
430
let mode = meta. attribute_uint32 ( "unix::mode" ) ;
431
431
h. set_mode ( self . filter_mode ( mode) ) ;
432
432
if instream. is_some ( ) {
433
+ h. set_entry_type ( tar:: EntryType :: Regular ) ;
433
434
h. set_size ( meta. size ( ) as u64 ) ;
435
+ } else {
436
+ h. set_entry_type ( tar:: EntryType :: Symlink ) ;
437
+ h. set_size ( 0 ) ;
434
438
}
435
439
if !self . wrote_content . contains ( checksum) {
436
440
let inserted = self . wrote_content . insert ( checksum. to_string ( ) ) ;
@@ -445,8 +449,6 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
445
449
if let Some ( instream) = instream {
446
450
ensure ! ( meta. file_type( ) == gio:: FileType :: Regular ) ;
447
451
448
- h. set_entry_type ( tar:: EntryType :: Regular ) ;
449
- h. set_size ( meta. size ( ) as u64 ) ;
450
452
let mut instream = BufReader :: with_capacity ( BUF_CAPACITY , instream. into_read ( ) ) ;
451
453
self . out
452
454
. append_data ( & mut h, & path, & mut instream)
@@ -461,8 +463,6 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
461
463
. to_str ( )
462
464
. ok_or_else ( || anyhow ! ( "Invalid UTF-8 symlink target: {target:?}" ) ) ?;
463
465
let context = || format ! ( "Writing content symlink: {}" , checksum) ;
464
- h. set_entry_type ( tar:: EntryType :: Symlink ) ;
465
- h. set_size ( 0 ) ;
466
466
// Handle //chkconfig, see above
467
467
if symlink_is_denormal ( target) {
468
468
h. set_link_name_literal ( target) . with_context ( context) ?;
@@ -501,15 +501,20 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
501
501
mut h : tar:: Header ,
502
502
dest : & Utf8Path ,
503
503
) -> Result < ( ) > {
504
- // Query the original size first
505
- let size = h. size ( ) . context ( "Querying size for hardlink append" ) ?;
506
504
// Don't create hardlinks to zero-sized files, it's much more likely
507
505
// to result in generated tar streams from container builds resulting
508
506
// in a modified linked-to file in /sysroot, which we don't currently handle.
509
507
// And in the case where the input is *not* zero sized, we still output
510
508
// a hardlink of size zero, as this is what is normal.
509
+ let is_regular_zerosized = if h. entry_type ( ) == tar:: EntryType :: Regular {
510
+ let size = h. size ( ) . context ( "Querying size for hardlink append" ) ?;
511
+ size == 0
512
+ } else {
513
+ false
514
+ } ;
515
+ // Link sizes shoud always be zero
511
516
h. set_size ( 0 ) ;
512
- if h . entry_type ( ) == tar :: EntryType :: Regular && size == 0 {
517
+ if is_regular_zerosized {
513
518
self . out . append_data ( & mut h, dest, & mut std:: io:: empty ( ) ) ?;
514
519
} else {
515
520
h. set_entry_type ( tar:: EntryType :: Link ) ;
@@ -549,7 +554,8 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
549
554
let ( objpath, h) = self . append_content ( checksum) ?;
550
555
let subpath = & dirpath. join ( name) ;
551
556
let subpath = map_path ( subpath) ;
552
- self . append_content_hardlink ( & objpath, h, & subpath) ?;
557
+ self . append_content_hardlink ( & objpath, h, & subpath)
558
+ . with_context ( || format ! ( "Hardlinking {checksum} to {subpath}" ) ) ?;
553
559
}
554
560
}
555
561
0 commit comments