@@ -21,7 +21,7 @@ use std::io::{ErrorKind, Read, Seek, SeekFrom, Write};
2121use  std:: ops:: Range ; 
2222use  std:: sync:: Arc ; 
2323use  std:: time:: SystemTime ; 
24- use  std:: { collections:: BTreeSet ,  convert :: TryFrom ,   io} ; 
24+ use  std:: { collections:: BTreeSet ,  io} ; 
2525use  std:: { collections:: VecDeque ,  path:: PathBuf } ; 
2626
2727use  async_trait:: async_trait; 
@@ -44,12 +44,6 @@ use crate::{
4444/// A specialized `Error` for filesystem object store-related errors 
4545#[ derive( Debug ,  thiserror:: Error ) ]  
4646pub ( crate )  enum  Error  { 
47-     #[ error( "File size for {} did not fit in a usize: {}" ,  path,  source) ]  
48-     FileSizeOverflowedUsize  { 
49-         source :  std:: num:: TryFromIntError , 
50-         path :  String , 
51-     } , 
52- 
5347    #[ error( "Unable to walk dir: {}" ,  source) ]  
5448    UnableToWalkDir  {  source :  walkdir:: Error  } , 
5549
@@ -83,8 +77,8 @@ pub(crate) enum Error {
8377    #[ error( "Out of range of file {}, expected: {}, actual: {}" ,  path. display( ) ,  expected,  actual) ]  
8478    OutOfRange  { 
8579        path :  PathBuf , 
86-         expected :  usize , 
87-         actual :  usize , 
80+         expected :  u64 , 
81+         actual :  u64 , 
8882    } , 
8983
9084    #[ error( "Requested range was invalid" ) ]  
@@ -410,7 +404,7 @@ impl ObjectStore for LocalFileSystem {
410404        let  path = self . path_to_filesystem ( & location) ?; 
411405        maybe_spawn_blocking ( move  || { 
412406            let  ( file,  metadata)  = open_file ( & path) ?; 
413-             let  meta = convert_metadata ( metadata,  location) ? ; 
407+             let  meta = convert_metadata ( metadata,  location) ; 
414408            options. check_preconditions ( & meta) ?; 
415409
416410            let  range = match  options. range  { 
@@ -430,7 +424,7 @@ impl ObjectStore for LocalFileSystem {
430424        . await 
431425    } 
432426
433-     async  fn  get_range ( & self ,  location :  & Path ,  range :  Range < usize > )  -> Result < Bytes >  { 
427+     async  fn  get_range ( & self ,  location :  & Path ,  range :  Range < u64 > )  -> Result < Bytes >  { 
434428        let  path = self . path_to_filesystem ( location) ?; 
435429        maybe_spawn_blocking ( move  || { 
436430            let  ( mut  file,  _)  = open_file ( & path) ?; 
@@ -439,7 +433,7 @@ impl ObjectStore for LocalFileSystem {
439433        . await 
440434    } 
441435
442-     async  fn  get_ranges ( & self ,  location :  & Path ,  ranges :  & [ Range < usize > ] )  -> Result < Vec < Bytes > >  { 
436+     async  fn  get_ranges ( & self ,  location :  & Path ,  ranges :  & [ Range < u64 > ] )  -> Result < Vec < Bytes > >  { 
443437        let  path = self . path_to_filesystem ( location) ?; 
444438        let  ranges = ranges. to_vec ( ) ; 
445439        maybe_spawn_blocking ( move  || { 
@@ -825,7 +819,7 @@ impl Drop for LocalUpload {
825819pub ( crate )  fn  chunked_stream ( 
826820    mut  file :  File , 
827821    path :  PathBuf , 
828-     range :  Range < usize > , 
822+     range :  Range < u64 > , 
829823    chunk_size :  usize , 
830824)  -> BoxStream < ' static ,  Result < Bytes ,  super :: Error > >  { 
831825    futures:: stream:: once ( async  move  { 
@@ -847,17 +841,23 @@ pub(crate) fn chunked_stream(
847841                        return  Ok ( None ) ; 
848842                    } 
849843
850-                     let  to_read = remaining. min ( chunk_size) ; 
851-                     let  mut  buffer = Vec :: with_capacity ( to_read) ; 
844+                     let  to_read = remaining. min ( chunk_size as  u64 ) ; 
845+                     let  cap = usize:: try_from ( to_read) . map_err ( |_e| Error :: InvalidRange  { 
846+                         source :  InvalidGetRange :: TooLarge  { 
847+                             requested :  to_read, 
848+                             max :  usize:: MAX  as  u64 , 
849+                         } , 
850+                     } ) ?; 
851+                     let  mut  buffer = Vec :: with_capacity ( cap) ; 
852852                    let  read = ( & mut  file) 
853-                         . take ( to_read  as   u64 ) 
853+                         . take ( to_read) 
854854                        . read_to_end ( & mut  buffer) 
855855                        . map_err ( |e| Error :: UnableToReadBytes  { 
856856                            source :  e, 
857857                            path :  path. clone ( ) , 
858858                        } ) ?; 
859859
860-                     Ok ( Some ( ( buffer. into ( ) ,  ( file,  path,  remaining - read) ) ) ) 
860+                     Ok ( Some ( ( buffer. into ( ) ,  ( file,  path,  remaining - read  as   u64 ) ) ) ) 
861861                } ) 
862862            } , 
863863        ) ; 
@@ -867,22 +867,18 @@ pub(crate) fn chunked_stream(
867867    . boxed ( ) 
868868} 
869869
870- pub ( crate )  fn  read_range ( file :  & mut  File ,  path :  & PathBuf ,  range :  Range < usize > )  -> Result < Bytes >  { 
870+ pub ( crate )  fn  read_range ( file :  & mut  File ,  path :  & PathBuf ,  range :  Range < u64 > )  -> Result < Bytes >  { 
871871    let  to_read = range. end  - range. start ; 
872-     file. seek ( SeekFrom :: Start ( range. start  as  u64 ) ) 
873-         . map_err ( |source| { 
874-             let  path = path. into ( ) ; 
875-             Error :: Seek  {  source,  path } 
876-         } ) ?; 
872+     file. seek ( SeekFrom :: Start ( range. start ) ) . map_err ( |source| { 
873+         let  path = path. into ( ) ; 
874+         Error :: Seek  {  source,  path } 
875+     } ) ?; 
877876
878-     let  mut  buf = Vec :: with_capacity ( to_read) ; 
879-     let  read = file
880-         . take ( to_read as  u64 ) 
881-         . read_to_end ( & mut  buf) 
882-         . map_err ( |source| { 
883-             let  path = path. into ( ) ; 
884-             Error :: UnableToReadBytes  {  source,  path } 
885-         } ) ?; 
877+     let  mut  buf = Vec :: with_capacity ( to_read as  usize ) ; 
878+     let  read = file. take ( to_read) . read_to_end ( & mut  buf) . map_err ( |source| { 
879+         let  path = path. into ( ) ; 
880+         Error :: UnableToReadBytes  {  source,  path } 
881+     } ) ? as  u64 ; 
886882
887883    if  read != to_read { 
888884        let  error = Error :: OutOfRange  { 
@@ -922,7 +918,7 @@ fn open_file(path: &PathBuf) -> Result<(File, Metadata)> {
922918
923919fn  convert_entry ( entry :  DirEntry ,  location :  Path )  -> Result < Option < ObjectMeta > >  { 
924920    match  entry. metadata ( )  { 
925-         Ok ( metadata)  => convert_metadata ( metadata,  location) . map ( Some ) , 
921+         Ok ( metadata)  => Ok ( Some ( convert_metadata ( metadata,  location) ) ) , 
926922        Err ( e)  => { 
927923            if  let  Some ( io_err)  = e. io_error ( )  { 
928924                if  io_err. kind ( )  == ErrorKind :: NotFound  { 
@@ -960,20 +956,16 @@ fn get_etag(metadata: &Metadata) -> String {
960956    format ! ( "{inode:x}-{mtime:x}-{size:x}" ) 
961957} 
962958
963- fn  convert_metadata ( metadata :  Metadata ,  location :  Path )  -> Result < ObjectMeta >  { 
959+ fn  convert_metadata ( metadata :  Metadata ,  location :  Path )  -> ObjectMeta  { 
964960    let  last_modified = last_modified ( & metadata) ; 
965-     let  size = usize:: try_from ( metadata. len ( ) ) . map_err ( |source| { 
966-         let  path = location. as_ref ( ) . into ( ) ; 
967-         Error :: FileSizeOverflowedUsize  {  source,  path } 
968-     } ) ?; 
969961
970-     Ok ( ObjectMeta  { 
962+     ObjectMeta  { 
971963        location, 
972964        last_modified, 
973-         size, 
965+         size :  metadata . len ( ) , 
974966        e_tag :  Some ( get_etag ( & metadata) ) , 
975967        version :  None , 
976-     } ) 
968+     } 
977969} 
978970
979971#[ cfg( unix) ]  
0 commit comments