earthstar-project / earthstar

Storage for private, distributed, offline-first applications.
https://earthstar-project.org
GNU Lesser General Public License v3.0
637 stars 20 forks source link

SyncFsOptions: added overwriteFilesAtOwnedPath option #249

Closed sgwilym closed 2 years ago

sgwilym commented 2 years ago

What's the problem you solved?

With the current implementation of syncReplicaAndFsDir, there are certain sequences of events that would cause errors about writing to unowned paths, even when the user hadn't done anything. For example:

0000: @aaaa sets /@aaaa/doc.txt to replica A .
0100: @bbbb syncs to replica B.
0150: @aaaa sets /@aaaa/doc.txt to replica A.
0200: @bbbb syncs to fs, writing /@aaaa.doc.txt (from 0000) to disk.
0300: @bbbb syncs replica B, getting latest doc written at 0150.
0400: @bbbb attempts sync to fs, but fails because their file (written  at 0200) has a newer timestamp and different hash to the doc set at @150 by @aaaa.

What solution are you recommending?

I've added an option which forcibly overwrites files at paths not owned by the given identity.