@@ -10,6 +10,7 @@ use std::{
1010} ;
1111
1212use clean_path:: clean;
13+ pub use hermit_image_reader:: thin_tree:: ThinTree as HermitImageThinTree ;
1314use tempfile:: TempDir ;
1415use uuid:: Uuid ;
1516
@@ -39,76 +40,12 @@ impl core::ops::Index<Range<usize>> for HermitImage {
3940 }
4041}
4142
42- #[ derive( Clone , Debug , PartialEq , Eq ) ]
43- pub enum HermitImageThinFile {
44- File ( Range < usize > ) ,
45- Directory ( HashMap < String , HermitImageThinFile > ) ,
46- }
47-
48- impl HermitImageThinFile {
49- /// Populate a thin directory tree, with `entry` pointing to `r`
50- pub fn update ( & mut self , entry : & [ & str ] , r : Range < usize > ) {
51- let mut this = self ;
52- for i in entry {
53- let dir = match this {
54- Self :: File ( r) if r. start == r. end => {
55- * this = Self :: Directory ( HashMap :: new ( ) ) ;
56- if let Self :: Directory ( dir) = this {
57- dir
58- } else {
59- unreachable ! ( )
60- }
61- }
62- Self :: File ( _) => panic ! ( "file in hermit image got overridden" ) ,
63- Self :: Directory ( dir) => dir,
64- } ;
65- this = dir
66- . entry ( i. to_string ( ) )
67- . or_insert ( HermitImageThinFile :: File ( 0 ..0 ) ) ;
68- }
69- * this = Self :: File ( r) ;
70- }
71-
72- /// Remove an entry from a thin directory tree
73- pub fn unlink ( & mut self , entry : & [ & str ] ) {
74- if entry. is_empty ( ) {
75- // we can't remove ourselves.
76- return ;
77- }
78- let ( lead, to_remove) = entry. split_at ( entry. len ( ) - 1 ) ;
79- let this = self . resolve_mut ( lead) ;
80- if let Some ( Self :: Directory ( this) ) = this {
81- this. remove ( to_remove[ 0 ] ) ;
82- }
83- }
84-
85- pub fn resolve ( & self , entry : & [ & str ] ) -> Option < & HermitImageThinFile > {
86- entry. iter ( ) . try_fold ( self , |this, & i| {
87- if let Self :: Directory ( dir) = this {
88- dir. get ( i)
89- } else {
90- None
91- }
92- } )
93- }
94-
95- pub fn resolve_mut ( & mut self , entry : & [ & str ] ) -> Option < & mut HermitImageThinFile > {
96- entry. iter ( ) . try_fold ( self , |this, & i| {
97- if let Self :: Directory ( dir) = this {
98- dir. get_mut ( i)
99- } else {
100- None
101- }
102- } )
103- }
104- }
105-
10643#[ derive( Clone , Debug ) ]
10744pub enum MappedFile {
10845 OnHost ( PathBuf ) ,
10946 InImage {
11047 image : Arc < HermitImage > ,
111- thin : HermitImageThinFile ,
48+ thin : HermitImageThinTree ,
11249 } ,
11350}
11451
@@ -117,7 +54,7 @@ pub enum MappedFileMutRef<'a> {
11754 OnHost ( PathBuf ) ,
11855 InImage {
11956 image : & ' a Arc < HermitImage > ,
120- thin : & ' a mut HermitImageThinFile ,
57+ thin : & ' a mut HermitImageThinTree ,
12158 } ,
12259}
12360
@@ -203,15 +140,8 @@ impl UhyveFileMap {
203140 let mmap = unsafe { MmapOptions :: new ( ) . map ( tmpf. as_file ( ) ) }
204141 . expect ( "unable to mmap decompressed hermit image file" ) ;
205142
206- let mut content = HermitImageThinFile :: File ( 0 ..0 ) ;
207- for i in hermit_image_reader:: ImageParser :: new ( & mmap[ ..] ) {
208- let i = i. expect ( "unable to read hermit image entry" ) ;
209- if let Ok ( name) = str:: from_utf8 ( & i. name ) {
210- // multiple entries with the same name might exist,
211- // latest entry wins / overwrites existing ones
212- content. update ( & name. split ( '/' ) . collect :: < Vec < _ > > ( ) , i. value_range ) ;
213- }
214- }
143+ let content = HermitImageThinTree :: try_from_image ( & mmap[ ..] )
144+ . expect ( "unable to parse hermit image file entry" ) ;
215145
216146 (
217147 Arc :: new ( HermitImage {
0 commit comments