OneDrive backend - Support for shared folders

I recently tried using a OneDrive shared folder as the storage destination, and ran into an error saying some operation could not be performed on a mounted folder (first described here: Moving OneDrive token files)

After further testing with the CLI with debug enabled, I found that CreateDirectory is the operation that is being rejected.

After quite a bit of trial and error (I’ve never used either the OneDrive API or the Go language, so this has been fun!) I now have “init” working with a shared folder. The changes to add this support can be viewed here: Trying to support shared storage · rickparrish/duplicacy@8fb4a20 · GitHub

“init” doesn’t appear to call ListEntries, DeleteFile, and MoveFile, so those changes have not been tested yet.

I was going to try backing up a test directory, but then I noticed there appears to be a test function for OneDrive that calls these methods, and thought that might be even better. Unfortunately I’m not sure how to invoke that test method! Is there a secret command-line parameter? Or some other way to call it?

Thanks,
Rick

1 Like

I think I figured this “go test” stuff out, and things appear to be working.

So @gchen assuming you’re OK with merging this feature, I’m wondering how you’d like it to function.

As you’ll see from the commit I tried to implement the changes with the least impact possible, so the original “drive/root:/{path}” url format is still used for owned folders, and the “drives/{driveid}/items/{itemid}:/{path}” url format is only used for shared folders.

But the url format I added for shared folders should also work for the owned folders (I assume anyway, I’d need to test to confirm), so another option would be to use that url format for both, eliminating all the if statements.

The other question is how to detect owned vs shared folders. I don’t really like the way I have DetectSharedStorage return GetFIleInfo, and that I changed duplicacy_onestorage.go to call DetectSharedStorage instead of GetFileInfo. Maybe DetectSharedStorage should be called in NewOneDriveClient, right at the end after client.RefreshToken(false) is called?

And then assuming all the urls are changed to use the new format, I think it would make sense to rename it from DetectSharedStorage to something else, maybe something like GetDriveID since it would have to retrieve the Drive and Item IDs for both the owned and shared scenarios?

EDIT: Here’s a preview of the changes where owned and shared folders both use the same url format: Comparing gilbertchen:master...rickparrish:master · gilbertchen/duplicacy · GitHub

Thanks,
Rick

Thanks for adding this feature. I’ll look through your changes and run a test myself.

You’re welcome. And thank you, for such a great piece of software.

If you’d like any of this submitted as a pull request, just let me know. I’m happy to re-do the implementation with whatever strategy you feel fits best with Duplicacy.