Skip to content
Permalink
Browse files

FileSystem>>move:to: do nothing if the source and destination are the…

… same
  • Loading branch information
akgrant committed Jan 11, 2019
1 parent dfde06b commit 232472a1663fc76747c8122e881d549f28f3268d
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/FileSystem-Core/FileSystem.class.st
@@ -610,17 +610,19 @@ FileSystem >> move: sourcePath to: destination [
If destPath is a file, raise FileExists.
If destPath is a directory, move the sourcePath in to the directory"

| fullDestination |
| fullDestination destinationPath |

destination isFile ifTrue: [ FileExists signalWith: destination ].
destination isDirectory
ifTrue: [ fullDestination := destination / sourcePath basename ]
ifFalse: [ fullDestination := destination ].
self = destination fileSystem ifTrue:
[
destinationPath := fullDestination resolve path.
sourcePath = destinationPath ifTrue: [ ^fullDestination ].
"Ideally we would test whether the source and destination are on the same filesystem from the OSs perspective.
Since we can't do that, just try rename, and if that fails, copy and delete."
[ self rename: sourcePath to: fullDestination resolve path ]
[ self rename: sourcePath to: destinationPath ]
on: Error
do: [ :error | self copyAndDelete: sourcePath to: fullDestination ].
] ifFalse:

0 comments on commit 232472a

Please sign in to comment.
You can’t perform that action at this time.