Duplicate Dropbox file created after prepend

I have a basic action that prepends the draft/selection to a Dropbox file. (The file name comes from a form spinner with hard-coded values.)

But every so often, a duplicate of that file is created.

I presume that’s a Dropbox issue / oddity? Something they’re doing if it thinks the file is locked, maybe.

Just reporting in case there’s logic in the Drafts app that may be causing this.

Any clues, like might this happen if you repeat the action multiple time quickly?

Those numbers are not added by Drafts, it’s how Dropbox resolves conflicts, but the requests Drafts is making explicitly tell the Dropbox API not to resolve conflicts and rather to throw an error, so that should certainly not be happening.

If I cannot reproduce in quick testing here, but that doesn’t prove much. Do you have any other process that work with the files you are appending to? Automations, open in other editors on other devices?

For what it’s worth, if it helps you troubleshoot or notice a pattern, Dropbox (and any of the other file-based services Drafts works with) has no API for appending-prepending. To do this Drafts actions:

  • Figure out the dynamic path/file name for the action.
  • Query the API to download the current version of that file.
  • If that file does not exist (previous step fails), upload as a new file
  • If that file does exist, read its contents, update it and upload the new version of the full content.

In the case of Dropbox, when the existing file is downloaded, it includes a revision number for the file, and that revision number is included with the call to update the file. In theory, if the revision number of the file has changed since the download (which is rare, it was moments earlier), Dropbox should (based on the parameters Dropbox sends) throw an error and not update the file because of conflict.

It appears, in some cases, Dropbox is treating the uploaded version as a conflict, and autorenaming it as if Drafts had passed different parameters.

Trying to think of clues…

  • No other process uses these files, haven’t been able to think of a reason a file is locked
  • Even though the file is duplicated, the write still happens on the file I requested – just copies are also made to these -1, -2 files
  • The action isn’t ever run quickly in succession – if I happened to prepend to the same file, it would be at least 10 seconds between actions (takes me that long to read, decide which file, use the spinner in the form, submit the form)

In fact, when I run this action, it also first writes to a different Dropbox file, representing the month. Acts just the same, but does an append. And there’s never been a duplicate file created. Strange.

Fwiw, this particular file has had hundreds of writes / revisions – so way more than the 7 copies currently.