1
1
use std:: {
2
2
cell:: RefCell ,
3
- cmp:: max,
4
3
collections:: { BTreeMap , HashMap } ,
5
4
ffi:: { CStr , OsStr } ,
6
5
fs:: File ,
@@ -145,7 +144,6 @@ pub fn write_to_path<ObjectID: FsVerityHashValue>(
145
144
pub struct FilesystemReader < ' repo , ObjectID : FsVerityHashValue > {
146
145
repo : Option < & ' repo Repository < ObjectID > > ,
147
146
inodes : HashMap < ( u64 , u64 ) , Rc < Leaf < ObjectID > > > ,
148
- root_mtime : Option < i64 > ,
149
147
}
150
148
151
149
impl < ObjectID : FsVerityHashValue > FilesystemReader < ' _ , ObjectID > {
@@ -269,6 +267,7 @@ impl<ObjectID: FsVerityHashValue> FilesystemReader<'_, ObjectID> {
269
267
& mut self ,
270
268
dirfd : impl AsFd ,
271
269
name : & OsStr ,
270
+ stat_self : bool ,
272
271
) -> Result < Directory < ObjectID > > {
273
272
let fd = openat (
274
273
dirfd,
@@ -277,8 +276,12 @@ impl<ObjectID: FsVerityHashValue> FilesystemReader<'_, ObjectID> {
277
276
Mode :: empty ( ) ,
278
277
) ?;
279
278
280
- let ( _, stat) = Self :: stat ( & fd, FileType :: Directory ) ?;
281
- let mut directory = Directory :: new ( stat) ;
279
+ let mut directory = if stat_self {
280
+ let ( _, stat) = Self :: stat ( & fd, FileType :: Directory ) ?;
281
+ Directory :: new ( stat)
282
+ } else {
283
+ Directory :: default ( )
284
+ } ;
282
285
283
286
for item in Dir :: read_from ( & fd) ? {
284
287
let entry = item?;
@@ -289,7 +292,6 @@ impl<ObjectID: FsVerityHashValue> FilesystemReader<'_, ObjectID> {
289
292
}
290
293
291
294
let inode = self . read_inode ( & fd, name, entry. file_type ( ) ) ?;
292
- self . root_mtime = max ( self . root_mtime , Some ( inode. stat ( ) . st_mtim_sec ) ) ;
293
295
directory. insert ( name, inode) ;
294
296
}
295
297
@@ -303,7 +305,7 @@ impl<ObjectID: FsVerityHashValue> FilesystemReader<'_, ObjectID> {
303
305
ifmt : FileType ,
304
306
) -> Result < Inode < ObjectID > > {
305
307
if ifmt == FileType :: Directory {
306
- let dir = self . read_directory ( dirfd, name) ?;
308
+ let dir = self . read_directory ( dirfd, name, true ) ?;
307
309
Ok ( Inode :: Directory ( Box :: new ( dir) ) )
308
310
} else {
309
311
let leaf = self . read_leaf ( dirfd, name, ifmt) ?;
@@ -315,19 +317,20 @@ impl<ObjectID: FsVerityHashValue> FilesystemReader<'_, ObjectID> {
315
317
pub fn read_from_path < ObjectID : FsVerityHashValue > (
316
318
path : & Path ,
317
319
repo : Option < & Repository < ObjectID > > ,
320
+ stat_root : bool ,
318
321
) -> Result < FileSystem < ObjectID > > {
319
322
let mut reader = FilesystemReader {
320
323
repo,
321
324
inodes : HashMap :: new ( ) ,
322
- root_mtime : None ,
323
325
} ;
326
+
327
+ let root = reader. read_directory ( CWD , path. as_os_str ( ) , stat_root) ?;
328
+
324
329
let mut fs = FileSystem {
325
- root : reader. read_directory ( CWD , path. as_os_str ( ) ) ?,
330
+ root,
331
+ have_root_stat : stat_root,
326
332
} ;
327
333
328
- // A filesystem with no files ends up in the 1970s...
329
- fs. root . stat . st_mtim_sec = reader. root_mtime . unwrap_or ( 0 ) ;
330
-
331
334
// We can only relabel if we have the repo because we need to read the config and policy files
332
335
if let Some ( repo) = repo {
333
336
selabel ( & mut fs, repo) ?;
@@ -340,7 +343,7 @@ pub fn create_image<ObjectID: FsVerityHashValue>(
340
343
path : & Path ,
341
344
repo : Option < & Repository < ObjectID > > ,
342
345
) -> Result < ObjectID > {
343
- let fs = read_from_path ( path, repo) ?;
346
+ let fs = read_from_path ( path, repo, false ) ?;
344
347
let image = crate :: erofs:: writer:: mkfs_erofs ( & fs) ;
345
348
if let Some ( repo) = repo {
346
349
Ok ( repo. write_image ( None , & image) ?)
@@ -350,7 +353,7 @@ pub fn create_image<ObjectID: FsVerityHashValue>(
350
353
}
351
354
352
355
pub fn create_dumpfile < ObjectID : FsVerityHashValue > ( path : & Path ) -> Result < ( ) > {
353
- let fs = read_from_path :: < ObjectID > ( path, None ) ?;
356
+ let fs = read_from_path :: < ObjectID > ( path, None , false ) ?;
354
357
super :: dumpfile:: write_dumpfile ( & mut std:: io:: stdout ( ) , & fs)
355
358
}
356
359
0 commit comments