Question

in C# I'm creating a client to sync local files and Dropbox folder, using DropNet lib.
If the same file is present both in the cloud and in the local folders, how do I check if they are equivalent, or which of the two is more up to date? If I compare the ModifiedDate of cloud file with LastWriteTime of local file, these dates are always conflicting, probably because the client time is different from the dropbox's server time. How can I make a efficient file compare?

Was it helpful?

Solution

The Dropbox API allows you to interface with the normal Dropbox ecosystem, and when syncing with Dropbox there may be well more than 2 clients on a single account. To reconcile this, the Dropbox servers are considered the source of truth. So, when you're syncing with Dropbox, the intention is that you should get all changes from the server, as well as report all local changes to the server, as soon as possible.

Along those lines, while the Dropbox API doesn't currently offer a way to get a file ID or hash for a remote file (though we're tacking this as a feature request) it does offer ways to know if files have changed remotely so that you can update your local state. One way to use the "rev" property of a file at a particular path via the /metadata API call:

https://www.dropbox.com/developers/core/docs#metadata

If the rev has changed since you last checked it, the file at that path has changed.

Another way is to use /delta:

https://www.dropbox.com/developers/core/docs#delta

You can occasionally call this to find out about any changes you need to make to your local state to get back up to date.

OTHER TIPS

A byte by byte comparison is probably the most correct approach. Read this link for a discussion on file hashes.

https://stackoverflow.com/a/7931320/1706610

And here's a nice link for a byte by byte file comparison method.

http://www.dotnetperls.com/file-equals

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top