pydio / pydio-core

Pydio 8 official repository
https://pydio.com
GNU Affero General Public License v3.0
867 stars 289 forks source link

restore folder from recycle_bin deletes existing folder with same name #1368

Closed ghost closed 6 years ago

ghost commented 7 years ago

Hello and thank you for the wonderful project.

We had a rather unfortunate data loss issue. If a folder with a given name "folder1" for example is in the recycle bin, and it is restored, if there exists a folder in the common area with the same name "folder1", the restore action completely removes all files in the common area's "folder1" and replaces it with the recycle bin version.

I believe that the recycle bin version should be renamed if the folder already exists, perhaps appending _restore or _restore_2 etc, if the folder already exists. Or perhaps, instead of silently deleting data, it simply gives an error in restoring.

I was able to reproduce this fairly easily:

what should happen?

the restore action should give an error "the folder already exists", or, perhaps it should restore to a new directory, and not silently delete the existing folder.

hschoenburg commented 7 years ago

Youch that is a nasty bug!

cdujeu commented 7 years ago

Hi! Thanks for reporting, that's indeed a nasty one. We'll have a look at that, I would be in favor of creating a new directory with -1 or -restored suffix. -c

ghost commented 7 years ago

Apparently the php "rename" function behavior is OS and filesystem type dependent, but generally it seems to say that "Attempts to rename oldname to newname, moving it between directories if necessary. If renaming a file and newname exists, it will be overwritten. If renaming a directory and newname exists, this function will emit a warning."

But it's not clear to me if restoring from recycle bin uses rename. It may be simply calling deldir first https://github.com/pydio/pydio-core/blob/68e50b20717fe764ee2ceccd41cf99e0850e8bcb/core/src/plugins/core.access/src/AbstractAccessDriver.php#L328