@@ -13,7 +13,6 @@ pub struct File {
1313 fd : FileDesc ,
1414}
1515
16- //TODO: We may be able to get some of this info
1716#[ derive( Clone ) ]
1817pub struct FileAttr {
1918 size : u64 ,
@@ -72,7 +71,6 @@ impl FileAttr {
7271
7372 let file_type = unsafe { vex_sdk:: vexFileStatus ( c_path. as_ptr ( ) ) } ;
7473 let is_dir = file_type == 3 ;
75- println ! ( "{is_dir}" ) ;
7674
7775 // We can't get the size if its a directory because we cant open it as a file
7876 if is_dir {
@@ -342,7 +340,7 @@ impl File {
342340 map_fresult ( vex_sdk:: vexFileSeek ( self . fd . 0 , try_convert_offset ( offset) ?, SEEK_SET ) ) ?
343341 } ,
344342
345- // The VEX SDK does not allow seeking with negative offsets.
343+ // vexOS does not allow seeking with negative offsets.
346344 // That means we need to calculate the offset from the start for both of these.
347345 SeekFrom :: End ( offset) => unsafe {
348346 // If our offset is positive, everything is easy
@@ -429,52 +427,15 @@ impl Drop for File {
429427 }
430428}
431429
432- pub fn readdir ( p : & Path ) -> io:: Result < ReadDir > {
433- // getting directory entries does not work with trailing slashes
434- let p = Path :: new (
435- p. to_str ( )
436- . ok_or ( io:: Error :: new (
437- io:: ErrorKind :: InvalidInput ,
438- "Path contained invalid characters" ,
439- ) ) ?
440- . trim_end_matches ( "/" ) ,
441- ) ;
442-
443- if !stat ( p) ?. file_type ( ) . is_dir ( ) {
444- return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput , "Given directory was not a path" ) ) ;
445- }
446-
447- let path = CString :: new ( p. as_os_str ( ) . as_encoded_bytes ( ) )
448- . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: InvalidInput , "Path contained a null byte" ) ) ?;
449-
450- //TODO: Figure out if there is any way to check the number of entries in a directory/the needed length
451- let mut filenames_buffer = [ 0u8 ; 1000 ] ;
452- unsafe {
453- vex_sdk:: vexFileDirectoryGet (
454- path. as_ptr ( ) ,
455- filenames_buffer. as_mut_ptr ( ) . cast ( ) ,
456- filenames_buffer. len ( ) as _ ,
457- ) ;
458- }
459- let filenames_buffer = filenames_buffer. to_vec ( ) ;
460- // stop at null-terminator
461- let filenames = match filenames_buffer. split ( |& e| e == 0 ) . next ( ) {
462- Some ( filenames) => filenames,
463- None => & filenames_buffer,
464- } ;
465- let filenames = String :: from_utf8 ( filenames. to_vec ( ) )
466- . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: InvalidData , "Path contained a null byte" ) ) ?;
467- let paths = filenames
468- . split ( '\n' )
469- . map ( |filename| {
470- let mut path = PathBuf :: new ( ) ;
471- path. push ( p) ;
472- path. push ( filename) ;
473- DirEntry { path }
474- } )
475- . collect :: < Vec < _ > > ( ) ;
476-
477- Ok ( ReadDir { entries : paths } )
430+ pub fn readdir ( _p : & Path ) -> io:: Result < ReadDir > {
431+ // While there *is* a userspace function for reading file directories,
432+ // the necessary implementation cannot currently be done cleanly, as
433+ // vexOS does not expose directory length to user programs.
434+ //
435+ // This means that we would need to create a large fixed-length buffer
436+ // and hope that the folder's contents didn't exceed that buffer's length,
437+ // which obviously isn't behavior we want to rely on in the standard library.
438+ unsupported ( )
478439}
479440
480441pub fn unlink ( _p : & Path ) -> io:: Result < ( ) > {
@@ -522,7 +483,7 @@ pub fn stat(p: &Path) -> io::Result<FileAttr> {
522483}
523484
524485pub fn lstat ( p : & Path ) -> io:: Result < FileAttr > {
525- // Symlinks aren't supported in our filesystem
486+ // Symlinks aren't supported in this filesystem
526487 stat ( p)
527488}
528489
0 commit comments