@@ -24,7 +24,7 @@ use composefs::{
2424 fsverity:: { FsVerityHashValue , Sha256HashValue , Sha512HashValue } ,
2525 generic_tree:: FileSystem ,
2626 repository:: Repository ,
27- tree:: RegularFile ,
27+ tree:: { Leaf , LeafContent , RegularFile , Stat } ,
2828} ;
2929use serde:: Serialize ;
3030
@@ -172,7 +172,7 @@ enum OciCommand {
172172 } ,
173173 /// Given a file path, get the file corresponding to it in the object store
174174 /// If the file if stored inline, returns an empty string
175- GetFileObjectRef {
175+ StatFile {
176176 #[ clap( flatten) ]
177177 config_opts : OCIConfigFilesystemOptions ,
178178 /// The absolute path of the file to be found
@@ -275,7 +275,7 @@ enum Command {
275275 } ,
276276 /// Given a file path, get the file corresponding to it in the object store
277277 /// If the file if stored inline, returns an empty string
278- GetFileObjectRef {
278+ StatFile {
279279 #[ clap( flatten) ]
280280 fs_opts : FsReadOptions ,
281281 /// The absolute path of the file to be found
@@ -299,13 +299,39 @@ enum Command {
299299
300300/// The return object of GetFileObjectRef cmd
301301#[ derive( Debug , Serialize ) ]
302- pub struct ObjectRef {
302+ pub struct ObjectRef < T : FsVerityHashValue > {
303303 /// Whether the file is stored inline in the EROFS image
304304 pub stored_inline : bool ,
305305 /// FsVerity digest of the file
306306 pub digest : Option < String > ,
307307 /// Path to the file relative to the object store
308308 pub path : Option < String > ,
309+ /// File metadata
310+ pub stat : Stat ,
311+ /// Whether the file is a regular file, symlink, etc.
312+ pub kind : LeafContent < T > ,
313+ }
314+
315+ impl < T : FsVerityHashValue > From < & Leaf < T > > for ObjectRef < T > {
316+ fn from ( leaf : & Leaf < T > ) -> Self {
317+ let ( stored_inline, digest, path) = match & leaf. content {
318+ LeafContent :: Regular ( file) => match file {
319+ RegularFile :: Inline ( ..) => ( true , None , None ) ,
320+ RegularFile :: External ( id, _) => {
321+ ( false , Some ( id. to_hex ( ) ) , Some ( id. to_object_pathname ( ) ) )
322+ }
323+ } ,
324+ _ => ( true , None , None ) ,
325+ } ;
326+
327+ Self {
328+ stored_inline,
329+ digest,
330+ path,
331+ stat : leaf. stat . clone ( ) ,
332+ kind : leaf. content . clone ( ) ,
333+ }
334+ }
309335}
310336
311337fn verity_opt < ObjectID > ( opt : & Option < String > ) -> Result < Option < ObjectID > >
@@ -385,26 +411,10 @@ fn load_filesystem_from_ondisk_fs<ObjectID: FsVerityHashValue>(
385411fn get_obj_ref_for_filesystem < ObjectID : FsVerityHashValue > (
386412 fs : & FileSystem < RegularFile < ObjectID > > ,
387413 file_path : & OsStr ,
388- ) -> Result < ObjectRef > {
414+ ) -> Result < ObjectRef < ObjectID > > {
389415 let ( dir, file) = fs. root . split ( file_path) ?;
390-
391- let obj_ref = dir. get_file ( file) ?;
392-
393- let obj_ref = match obj_ref {
394- RegularFile :: Inline ( ..) => ObjectRef {
395- stored_inline : true ,
396- digest : None ,
397- path : None ,
398- } ,
399-
400- RegularFile :: External ( id, _) => ObjectRef {
401- stored_inline : false ,
402- digest : Some ( id. to_hex ( ) ) ,
403- path : Some ( id. to_object_pathname ( ) ) ,
404- } ,
405- } ;
406-
407- Ok ( obj_ref)
416+ let leaf = dir. ref_leaf ( file) ?;
417+ Ok ( ObjectRef :: from ( leaf. as_ref ( ) ) )
408418}
409419
410420async fn run_cmd_with_repo < ObjectID > ( repo : Repository < ObjectID > , args : App ) -> Result < ( ) >
@@ -443,7 +453,7 @@ where
443453 let fs = load_filesystem_from_oci_image ( & repo, config_opts) ?;
444454 fs. print_dumpfile ( ) ?;
445455 }
446- OciCommand :: GetFileObjectRef {
456+ OciCommand :: StatFile {
447457 config_opts,
448458 file_path,
449459 } => {
@@ -644,7 +654,7 @@ where
644654 let id = fs. compute_image_id ( ) ;
645655 println ! ( "{}" , id. to_hex( ) ) ;
646656 }
647- Command :: GetFileObjectRef { fs_opts, file_path } => {
657+ Command :: StatFile { fs_opts, file_path } => {
648658 let fs = load_filesystem_from_ondisk_fs ( & fs_opts, & repo) ?;
649659 let obj_ref = get_obj_ref_for_filesystem ( & fs, file_path. as_os_str ( ) ) ?;
650660 serde_json:: to_writer ( std:: io:: stdout ( ) . lock ( ) , & obj_ref) ?;
0 commit comments