Skip to content

Conversation

@jul13579
Copy link
Contributor

@jul13579 jul13579 commented Jan 5, 2024

Purpose

This PR changes behaviour of syncthing related to receive-only folders, which I believe to be a bug since I wouldn't expect the current behaviour. With the current syncthing codebase, a file of a receive-only folder that is only modified locally can cause the creation of a .sync-conflict file.

Testing

Consider this szenario: Setup two paired clients that sync a folder with a given file (e.g. Test.txt). One of the clients configures the folder to be receive-only. Now, change the contents of the file for the receive-only client twice.

With the current syncthing codebase, this leads to the creation of a .sync-conflict file that contains the modified contents, while the regular Test.txt file is reset to the cluster's provided contents. This is due to a protocol.FileInfo#ShouldConflict check, that is succeeding on the locally modified file.

This PR changes this behaviour to not reset the file and not cause the creation of a .sync-conflict. Instead, the second content update is treated the same as the first content update.

This PR also contains a test that fails on the current codebase and succeeds with the changes introduced in this PR.

Screenshots

This is not a GUI change

Documentation

This is not a user visible change.

Authorship

Your name and email will be added automatically to the AUTHORS file
based on the commit metadata.

Thanks to all the syncthing folks for this awesome piece of software!

Comment on lines -419 to +426
if curFile.ShouldConflict() {
if curFile.ShouldConflict() && !f.ShouldConflict() {
// The old file was invalid for whatever reason and probably not
// up to date with what was out there in the cluster. Drop all
// others from the version vector to indicate that we haven't
// taken their version into account, and possibly cause a
// conflict.
// conflict. However, only do this if the new file is not also
// invalid. This would indicate that the new file is not part
// of the cluster, but e.g. a local change.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During my debugging session I could only see the issue happening during walkRegular. However I found similar checks in walkDir and walkSymlink, which I applied the same changes to - just for good measure.

@jul13579 jul13579 marked this pull request as ready for review January 5, 2024 07:21
@jul13579 jul13579 force-pushed the fix-readonly-file-sync branch from 0bf76a8 to 49032ec Compare January 5, 2024 07:23
Copy link
Member

@imsodin imsodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, nice catch!

One tiny nit about a test comment, otherwise lgtm.

Co-authored-by: Simon Frei <freisim93@gmail.com>
@imsodin imsodin changed the title Fix ReceiveOnly file sync lib/scanner: Prevent sync-conflict for receive-only local modifications Jan 8, 2024
@imsodin imsodin merged commit 8edd67a into syncthing:main Jan 8, 2024
calmh added a commit to calmh/syncthing that referenced this pull request Jan 14, 2024
* main: (24 commits)
  lib/ignore: Refactor out result type (syncthing#9343)
  build: Testing infra images for infra-* branches
  lib/versioner: Expand tildes in version directory (fixes syncthing#9241) (syncthing#9327)
  lib/scanner: Prevent sync-conflict for receive-only local modifications  (syncthing#9323)
  gui, man, authors: Update docs, translations, and contributors
  Fix website security link in README.md (syncthing#9325)
  cmd/syncthing: Add CLI completion functionality (fixes syncthing#8616) (syncthing#9226)
  lib/api: Save session & CSRF tokens to database, add option to stay logged in (fixes syncthing#9151) (syncthing#9284)
  Update dependencies (syncthing#9321)
  gui: Always inform about loading data in Restore Versions modal (syncthing#9317)
  lib/build: Allow semver build in version regex (fixes syncthing#9267) (syncthing#9316)
  gui: Keep short deviceID length consistent + xrefs (fixes syncthing#9313) (syncthing#9314)
  build(deps): bump actions/download-artifact from 3 to 4 (syncthing#9294)
  build(deps): bump actions/upload-artifact from 3 to 4 (syncthing#9293)
  gui, man, authors: Update docs, translations, and contributors
  gui, lib/scanner: Improve scan progress indication (ref syncthing#8331) (syncthing#9308)
  lib/protocol: handle empty names in unixOwnershipEqual (fixes syncthing#9039) (syncthing#9306)
  gui, man, authors: Update docs, translations, and contributors
  etc/linux-desktop: use double dash for long options (syncthing#9301)
  lib/connections: Skip allocation in check for missing port (syncthing#9297)
  ...
@calmh calmh added this to the v1.27.3 milestone Jan 22, 2024
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Apr 9, 2025
@syncthing syncthing locked and limited conversation to collaborators Apr 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants