File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2510,11 +2510,13 @@ fn copy_file(
25102510 }
25112511
25122512 if options. dereference ( source_in_command_line) {
2513- if let Ok ( src) = canonicalize ( source, MissingHandling :: Normal , ResolveMode :: Physical ) {
2514- if src. exists ( ) {
2515- copy_attributes ( & src, dest, & options. attributes ) ?;
2516- }
2517- }
2513+ // Try to canonicalize, but if it fails (e.g., due to inaccessible parent directories),
2514+ // fall back to the original source path
2515+ let src_for_attrs = canonicalize ( source, MissingHandling :: Normal , ResolveMode :: Physical )
2516+ . ok ( )
2517+ . filter ( |p| p. exists ( ) )
2518+ . unwrap_or_else ( || source. to_path_buf ( ) ) ;
2519+ copy_attributes ( & src_for_attrs, dest, & options. attributes ) ?;
25182520 } else if source_is_stream && !source. exists ( ) {
25192521 // Some stream files may not exist after we have copied it,
25202522 // like anonymous pipes. Thus, we can't really copy its
You can’t perform that action at this time.
0 commit comments