@@ -16,7 +16,7 @@ use cap_std_ext::dirext::CapStdExtDirExt;
16
16
use composefs:: fsverity:: { FsVerityHashValue , Sha256HashValue , Sha512HashValue } ;
17
17
use composefs:: generic_tree:: { Directory , Inode , Leaf , LeafContent , Stat } ;
18
18
use composefs:: tree:: ImageError ;
19
- use rustix:: fs:: readlinkat;
19
+ use rustix:: fs:: { AtFlags , Gid , Uid , readlinkat} ;
20
20
21
21
#[ derive( Debug ) ]
22
22
struct CustomMetadata {
@@ -195,7 +195,6 @@ fn get_modifications(
195
195
. extend ( collect_all_files ( & curr_dir, current_path. clone ( ) ) ) ;
196
196
}
197
197
198
- // TODO: Test if a file was changed to a directory
199
198
Err ( e) => Err ( e) ?,
200
199
}
201
200
}
@@ -439,19 +438,14 @@ fn create_dir_with_perms(
439
438
. set_permissions ( & dir_name, Permissions :: from_mode ( stat. st_mode ) )
440
439
. context ( format ! ( "Changing permissions for dir {dir_name:?}" ) ) ?;
441
440
442
- println ! (
443
- "Set permission of {dir_name:?} to {:?}" ,
444
- Permissions :: from_mode( stat. st_mode)
445
- ) ;
446
-
447
- // TODO: Handle ownership
448
- //
449
- // rustix::fs::chown(
450
- // &modified,
451
- // Some(Uid::from_raw(current_inode.stat().st_uid)),
452
- // Some(Gid::from_raw(current_inode.stat().st_gid)),
453
- // )
454
- // .context(format!("chown {modified:?}"))?;
441
+ rustix:: fs:: chownat (
442
+ & new_etc_fd,
443
+ dir_name,
444
+ Some ( Uid :: from_raw ( stat. st_uid ) ) ,
445
+ Some ( Gid :: from_raw ( stat. st_gid ) ) ,
446
+ AtFlags :: SYMLINK_NOFOLLOW ,
447
+ )
448
+ . context ( format ! ( "chown {dir_name:?}" ) ) ?;
455
449
456
450
Ok ( ( ) )
457
451
}
@@ -528,22 +522,8 @@ fn handle_modified_files(
528
522
// Directory exists in the new /etc, but was modified in some way
529
523
Ok ( ( dir, filename) ) => {
530
524
let new_inode = dir. lookup ( filename) ;
531
- // println!("new_inode: {new_inode:?}");
532
-
533
525
let ty = match current_inode {
534
526
Inode :: Directory ( ..) => {
535
- // let remove = match new_inode {
536
- // // Dir with the same name is present in new /etc
537
- // // We delete this dir and create a new one
538
- // Some(Inode::Directory(..)) => true,
539
-
540
- // // Dir doesn't exist in the new /etc, so create it
541
- // // Nothing to remove
542
- // None => false,
543
-
544
- // _ => anyhow::bail!("Dir {file:?} converted to file"),
545
- // };
546
-
547
527
create_dir_with_perms ( new_etc_fd, file, current_inode. stat ( ) , true ) ?;
548
528
549
529
"dir"
@@ -852,13 +832,23 @@ mod tests {
852
832
c. create_dir_all ( "dir/perms" ) ?;
853
833
c. set_permissions ( "dir/perms" , Permissions :: from_mode ( 0o777 ) ) ?;
854
834
835
+ // Directory ownership
836
+ p. create_dir_all ( "dir/owner" ) ?;
837
+
838
+ c. create_dir_all ( "dir/owner" ) ?;
839
+ rustix:: fs:: chownat (
840
+ & c,
841
+ "dir/owner" ,
842
+ Some ( Uid :: from_raw ( u16:: MAX as u32 ) ) ,
843
+ Some ( Gid :: from_raw ( u16:: MAX as u32 ) ) ,
844
+ AtFlags :: SYMLINK_NOFOLLOW ,
845
+ ) ?;
846
+
855
847
let ( pristine_etc_files, current_etc_files, new_etc_files) = traverse_etc ( & p, & c, & n) ?;
856
848
let diff = compute_diff ( & pristine_etc_files, & current_etc_files) ?;
857
849
println ! ( "current_etc_files: {current_etc_files:#?}" ) ;
858
850
merge ( & c, & current_etc_files, & n, & new_etc_files, diff) ?;
859
851
860
- // std::thread::sleep(std::time::Duration::from_secs(4434));
861
-
862
852
assert ! ( files_eq( & c, & n, "new_file.txt" ) ?) ;
863
853
assert ! ( files_eq( & c, & n, "a/new_file.txt" ) ?) ;
864
854
assert ! ( files_eq( & c, & n, "a/b/new_file.txt" ) ?) ;
@@ -892,6 +882,11 @@ mod tests {
892
882
n. metadata( "dir/perms" ) ?
893
883
) ) ;
894
884
885
+ assert ! ( compare_meta(
886
+ c. metadata( "dir/owner" ) ?,
887
+ n. metadata( "dir/owner" ) ?
888
+ ) ) ;
889
+
895
890
Ok ( ( ) )
896
891
}
897
892
}
0 commit comments