Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backups not working in the root directory. Fixes #327. #376

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

Jackabomb
Copy link
Contributor

@Jackabomb Jackabomb commented Apr 18, 2023

Whenever GoogleDriveStorageProvider receives the empty string as a path argument, it will now treat it as a synonymn for "root" instead of passing it through to the API. Note, the paths "/", "//", "///", and so on are equally invalid and should probably be treated similarly, but that is not addressed here.

Fixes #327.
Maybe helps with #167 and part of #228.
I suspect #296 might benefit from a similar approach, because I ran into the "multiple backup files being created before giving an error" issue with Google Drive at one point while working on this.

This is an alternative approach to my previous abandoned PR #375. I thought this might be cleaner, but maybe the one-liner there is better. You pick. I don't know the project well enough to say which one is cleaner.

Whenever GoogleDriveStorageProvider receives the empty string as a path argument, it will now treat it as a synonymn for "root" instead of passing it through to the API.
Note, the paths "/", "//", "///", and so on are equally invalid and should probably be treated similarly, but that is not addressed here.
@Jackabomb
Copy link
Contributor Author

This issue happens because CloudPath.GetDirectoryName() is used by GoogleDriveStorageProvider.Copy() in order to verify the containing folder already exists (and throw an error otherwise). But when the database is under the root, then the string passed to CloudPath.GetDirectoryName() is like "database.kdbx", so GetDirectoryName returns the empty string. This empty string is passed to GoogleDriveHelper.GetFileByPath, which returns null, because the Google Drive doesn't use the empty string for anything so the Files.List() query returns nothing.

This gets overwritten for anything not in the drive root, so newly-copied backups in the drive root have their parent explicitly set to root, instead of inheriting it from the source file.
Apparently this is how the Google Drive API treats copies with File unset or set to an empty list: the newly-created copy inherits the Parents list of the source file it was copied from.

This will fix a future incompatibility between root backups and shortcuts.
If a shortcut exists in the root, and we try to back it up, the backups should appear alongside the shortcut.
However, unless we set the parent to root, they would inherit the target's parent directory and appear alongside the target in it's home directory (wherever in the drive that might be).
@Kyrodan Kyrodan merged commit 53cb5a5 into Kyrodan:master Jun 17, 2024
@Kyrodan Kyrodan added this to the 2.1.0 milestone Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remote backup doesn't work on google drive in the root path
2 participants