flysystem
flysystem copied to clipboard
V2: Moving and Copying do not overwrite target location
Not sure if this a documentation error or a bug.
According to https://flysystem.thephpleague.com/v2/docs/usage/filesystem-api/
Moving and copying are both deterministic operations. This means they will always overwrite the target location
The function move()
can move both files and folders.
The term "target location" (as opposed to "target file") implies both files and folders.
However, the target is overwritten only when the source and destination are both files. e.g.
php > require 'vendor/autoload.php';
php > $a = new League\Flysystem\Local\LocalFilesystemAdapter('tmp');
php > $f = new League\Flysystem\Filesystem($a);
php > $f->write('foo', 'FOO');
php > $f->createDirectory('bar');
php > $f->move('foo', 'bar'); // I expect 'bar' to be overwritten
Warning: Uncaught League\Flysystem\UnableToMoveFile: Unable to move file from tmp/foo to tmp/bar
If this is a documentation error, then I would need to call delete($destination)
or deleteDirectory($destination)
first.
However there is no direct way to test if $destination
is a file or directory. I could listContents()
on the parent directory, filter by filename, then call isDir()
or isFile()
on the attributes object - but that seems somewhat inefficient.
When testing this in bash, then foo
will be moved inside bar
. So Im not sure that I would expect bar
to be overwritten as you say.
Im not sure that I would expect bar to be overwritten as you say.
I expect it because the documentation says explicitly "… will always overwrite the target …".
So either the code or the documenation should be changed.
Then, if it is a documentation error, I need some way to manually delete the target first - which means I need to know whether the existing target is a file or a directory.
FYI - my use-case is an image library, where photo.jpg
could either be a file or it could be a folder containing various cropped/scaled versions of the original file. Hence my copy/move/upload operations need to delete any existing file or folder first
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@stalebot - please keep this issue open
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@stalebot - this issue still exists in version 3 - please keep it open.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@stalebot - this issue still exists in the latest code - please keep it open.
We can confirm that the issue exists as described for the local adapter AND for the FTP adapter.
rename()
returns false, if the directory to be renamed to already exists: https://github.com/thephpleague/flysystem/blob/3.x/src/Local/LocalFilesystemAdapter.php#L266