@@ -598,7 +598,10 @@ impl ObjectStore for LocalFileSystem {
598
598
}
599
599
Err ( source) => match source. kind ( ) {
600
600
ErrorKind :: AlreadyExists => id += 1 ,
601
- ErrorKind :: NotFound => create_parent_dirs ( & to, source) ?,
601
+ ErrorKind :: NotFound => match from. exists ( ) {
602
+ true => create_parent_dirs ( & to, source) ?,
603
+ false => return Err ( Error :: NotFound { path : from, source } . into ( ) ) ,
604
+ } ,
602
605
_ => return Err ( Error :: UnableToCopyFile { from, to, source } . into ( ) ) ,
603
606
} ,
604
607
}
@@ -613,7 +616,10 @@ impl ObjectStore for LocalFileSystem {
613
616
match std:: fs:: rename ( & from, & to) {
614
617
Ok ( _) => return Ok ( ( ) ) ,
615
618
Err ( source) => match source. kind ( ) {
616
- ErrorKind :: NotFound => create_parent_dirs ( & to, source) ?,
619
+ ErrorKind :: NotFound => match from. exists ( ) {
620
+ true => create_parent_dirs ( & to, source) ?,
621
+ false => return Err ( Error :: NotFound { path : from, source } . into ( ) ) ,
622
+ } ,
617
623
_ => return Err ( Error :: UnableToCopyFile { from, to, source } . into ( ) ) ,
618
624
} ,
619
625
}
@@ -636,7 +642,10 @@ impl ObjectStore for LocalFileSystem {
636
642
}
637
643
. into ( ) )
638
644
}
639
- ErrorKind :: NotFound => create_parent_dirs ( & to, source) ?,
645
+ ErrorKind :: NotFound => match from. exists ( ) {
646
+ true => create_parent_dirs ( & to, source) ?,
647
+ false => return Err ( Error :: NotFound { path : from, source } . into ( ) ) ,
648
+ } ,
640
649
_ => return Err ( Error :: UnableToCopyFile { from, to, source } . into ( ) ) ,
641
650
} ,
642
651
}
@@ -990,6 +999,7 @@ mod tests {
990
999
list_with_delimiter ( & integration) . await ;
991
1000
rename_and_copy ( & integration) . await ;
992
1001
copy_if_not_exists ( & integration) . await ;
1002
+ copy_rename_nonexistent_object ( & integration) . await ;
993
1003
stream_get ( & integration) . await ;
994
1004
put_opts ( & integration, false ) . await ;
995
1005
}
0 commit comments