jstaf / onedriver

A native Linux filesystem for Microsoft OneDrive
GNU General Public License v3.0
1.94k stars 96 forks source link

Moving a directory over to an existing directory #160

Closed vpont closed 3 years ago

vpont commented 3 years ago

When moving a directory to one with the same name inside OneDrive's drive it will replace it instead of merging the files from both directories (as any other filesystem in Linux would do).

It can be reproduced as follows:

mkdir ~/OneDrive/testdir
touch ~/OneDrive/testdir/file1
mkdir /tmp/testdir
touch /tmp/testdir/file2
mv /tmp/testdir ~/OneDrive/

After this, only file2 will survive.

jstaf commented 3 years ago

Interesting, that's some really unfortunate behavior. I took a brief look at the code and it looks like as long as the OneDrive API allows creating a directory on top of an existing directory, the filesystem will just happily overwrite the existing directory in-place. I'll add some tests and fix this for the future.

Note that any lost files from this should still be available in the OneDrive Recycle Bin (you can view this in the OneDrive web UI).

jstaf commented 3 years ago

This is fixed now in #161.

One thing worth noting is that the final command in the test case mv /tmp/testdir ~/OneDrive/ is an "inter-device move" which mv treats differently than a normal move. Instead of merging the directory contents, mv will attempt to delete the destination directory before moving the source directory to the new location.

In this case, instead of merging the contents of the two directories, the correct behavior is for the mv command to fail when attempting to delete ~/OneDrive/testdir (because the destination directory is nonempty). The filesystem should do this properly now.