Version History in google drive (when using vim)

This was discussed originally back in November of 2021

In that discussion there was a statement made that perhaps rclone's mount logic could watch for vim's file behavior if it was known what vim does.

It was also suggested to "disable the swapfile" in vim, however that isn't a valid workaround. If swapfile is set, then the active buffer is written periodically to a swap file. If it is not set then the active buffer is only in ram. This, however, has no effect on the mv, write, delete operation that happens whenever a user uses :w or :save

Today I was frustrated by this exact issue and found a relevant vim-specific stack overflow post. Over there, the original questioner showed how they used ionotify to see what vim was doing during file save.

The work around is to set backupcopy=yes. Why this works is explained on :help backupcopy in vim. Mine was set to auto, which is the same as no it seems. Basically with set backupcopy=yes then vim makes a copy of the original file, edits the original file, and then deletes the backupcopy if all was successful. (If swapfile is set, changes are written to the swapfile, the backup is made, the swapfile is moved over the original file, and then the backup is deleted).

The "broken" behavior is if backupcopy=no, then the original file is renamed, a new file is written with the original file name, and then the original (now renamed) file is deleted. This seems to happen fast enough that rclone doesn't seem to notice the rename, as the file that shows up in my trash has the original file name.

It would be great if rclone worked with vim's default settings, as setting backupcopy=yes does slow down file io a bit. But this also seems like something that would be a bit brittle to detect.

As a new forum user I'm not allowed to add a 3rd link. But here's the vim help text on the web

Does rclone save the file data properly though? Is it just the name of the trashed file which is wrong?

In order for versions to be maintained in google drive, rclone has to update an existing file, so that is why the backupcopy=no doesn't maintain the versions.

I'm suprised about the name of the trashed file - these should happen in sequence so there should be no possibility of the rename being missed. I wonder if google drive itself is missing the rename.

Rclone will be deleting the file with the given ID not by name so I would be suprised if this was some Google drive eventual consistency thing.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.