@@ -4,7 +4,6 @@ use std::path::PathBuf;
44use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
55
66use clap:: Parser ;
7- use fastvint:: ReadVintExt ;
87use fuser:: {
98 FileAttr , FileType , Filesystem , MountOption , ReplyAttr , ReplyData , ReplyDirectory , ReplyEmpty ,
109 ReplyEntry , Request ,
@@ -92,16 +91,18 @@ const TTL: Duration = Duration::from_secs(1);
9291
9392fn parse_archive_time ( meta : & BoxMetadata , name : & str ) -> Option < SystemTime > {
9493 let bytes = meta. file_attr ( name) ?;
95- let mut cursor = std:: io:: Cursor :: new ( bytes. as_slice ( ) ) ;
96- let minutes = cursor. read_vi64 ( ) . ok ( ) ?;
94+ let ( minutes, len) = fastvint:: decode_vi64_slice ( bytes. as_slice ( ) ) ;
95+ if len == 0 {
96+ return None ;
97+ }
9798 let unix_secs = ( minutes * 60 + BOX_EPOCH_UNIX ) as u64 ;
9899 UNIX_EPOCH . checked_add ( Duration :: from_secs ( unix_secs) )
99100}
100101
101102fn archive_uid ( meta : & BoxMetadata ) -> u32 {
102103 if let Some ( bytes) = meta. file_attr ( "unix.uid" ) {
103- let mut cursor = std :: io :: Cursor :: new ( bytes. as_slice ( ) ) ;
104- if let Ok ( uid ) = cursor . read_vu32 ( ) {
104+ let ( uid , len ) = fastvint :: decode_vu32_slice ( bytes. as_slice ( ) ) ;
105+ if len > 0 {
105106 return uid;
106107 }
107108 }
@@ -110,8 +111,8 @@ fn archive_uid(meta: &BoxMetadata) -> u32 {
110111
111112fn archive_gid ( meta : & BoxMetadata ) -> u32 {
112113 if let Some ( bytes) = meta. file_attr ( "unix.gid" ) {
113- let mut cursor = std :: io :: Cursor :: new ( bytes. as_slice ( ) ) ;
114- if let Ok ( gid ) = cursor . read_vu32 ( ) {
114+ let ( gid , len ) = fastvint :: decode_vu32_slice ( bytes. as_slice ( ) ) ;
115+ if len > 0 {
115116 return gid;
116117 }
117118 }
@@ -203,16 +204,15 @@ impl RecordExt for box_format::Record<'_> {
203204 fn perm ( & self , meta : & BoxMetadata ) -> u16 {
204205 match self . attr ( meta, "unix.mode" ) {
205206 Some ( bytes) => {
206- let mut cursor = std:: io:: Cursor :: new ( bytes) ;
207- match cursor. read_vu32 ( ) {
208- Ok ( mode) => ( mode & 0o7777 ) as u16 ,
209- Err ( _) => {
210- use box_format:: Record :: * ;
211- match self {
212- File ( _) => 0o644 ,
213- Directory ( _) => 0o755 ,
214- Link ( _) => 0o644 ,
215- }
207+ let ( mode, len) = fastvint:: decode_vu32_slice ( bytes) ;
208+ if len > 0 {
209+ ( mode & 0o7777 ) as u16
210+ } else {
211+ use box_format:: Record :: * ;
212+ match self {
213+ File ( _) => 0o644 ,
214+ Directory ( _) => 0o755 ,
215+ Link ( _) => 0o644 ,
216216 }
217217 }
218218 }
@@ -230,15 +230,15 @@ impl RecordExt for box_format::Record<'_> {
230230 fn uid ( & self , meta : & BoxMetadata ) -> u32 {
231231 // Try record attribute
232232 if let Some ( bytes) = self . attr ( meta, "unix.uid" ) {
233- let mut cursor = std :: io :: Cursor :: new ( bytes) ;
234- if let Ok ( uid ) = cursor . read_vu32 ( ) {
233+ let ( uid , len ) = fastvint :: decode_vu32_slice ( bytes) ;
234+ if len > 0 {
235235 return uid;
236236 }
237237 }
238238 // Try archive-level default
239239 if let Some ( bytes) = meta. file_attr ( "unix.uid" ) {
240- let mut cursor = std :: io :: Cursor :: new ( bytes) ;
241- if let Ok ( uid ) = cursor . read_vu32 ( ) {
240+ let ( uid , len ) = fastvint :: decode_vu32_slice ( bytes) ;
241+ if len > 0 {
242242 return uid;
243243 }
244244 }
@@ -249,15 +249,15 @@ impl RecordExt for box_format::Record<'_> {
249249 fn gid ( & self , meta : & BoxMetadata ) -> u32 {
250250 // Try record attribute
251251 if let Some ( bytes) = self . attr ( meta, "unix.gid" ) {
252- let mut cursor = std :: io :: Cursor :: new ( bytes) ;
253- if let Ok ( gid ) = cursor . read_vu32 ( ) {
252+ let ( gid , len ) = fastvint :: decode_vu32_slice ( bytes) ;
253+ if len > 0 {
254254 return gid;
255255 }
256256 }
257257 // Try archive-level default
258258 if let Some ( bytes) = meta. file_attr ( "unix.gid" ) {
259- let mut cursor = std :: io :: Cursor :: new ( bytes) ;
260- if let Ok ( gid ) = cursor . read_vu32 ( ) {
259+ let ( gid , len ) = fastvint :: decode_vu32_slice ( bytes) ;
260+ if len > 0 {
261261 return gid;
262262 }
263263 }
0 commit comments