Skip to content

gui, lib: Fix tracking deleted locally-changed on encrypted (fixes #7715) - #7726

Merged
calmh merged 7 commits into
syncthing:mainfrom
imsodin:all/encryption-deleted
Nov 10, 2021
Merged

calmh merged 7 commits into
syncthing:mainfrom
imsodin:all/encryption-deleted

Conversation

@imsodin

@imsodin imsodin commented May 31, 2021

Copy link
Copy Markdown
Member

This PR removes the ugly hack explained in #7715:

The ugly hack is to ignore all items that have the locally-changed flag set and are deleted. That's fine for actually spurious files, that were removed, but obviously not for files that should be there.

Instead it adds the non-ugly, but somewhat scary ability to remove file infos from the database. We already do that, but only in bulk when a device changes index-id/is removed. It isn't rocket science, it's just the half of updateLocalFiles that removes the old file. The scary bit is just that the code it touches is already scary.
An alternative to this approach would be adding a new flag (e.g. FlagLocalReceiveEncryptedDeleted) and mark locally-changed, deleted items in receive-encrypted folders with that flag. This sidesteps the database changes, but instead of getting rid of useless file-infos, it keeps them with a new flag. That's why I'd prefer the db variant.

To facilitate removing as well as updating files while scanning, I added a scanBatch type with Update and Remove methods, that replaces the batchAppendFunction that was passed around as a function argument before.

Testing

Added one new test that ensures that spurious files added to either receive-only or receive-encrypted folders, that are subsequently deleted, don't show up as locally-changed. And extended an existing test to check the same thing.

@calmh

calmh commented Jun 3, 2021

Copy link
Copy Markdown
Member

Can you explain in human words what the mechanism here is? I don't fully follow.

@imsodin imsodin changed the title gui, lib: Fix tracking deleted locally-changed on encrypted (fixes #7708) gui, lib: Fix tracking deleted locally-changed on encrypted (fixes #7715) Jun 3, 2021
@imsodin

imsodin commented Jun 3, 2021

Copy link
Copy Markdown
Member Author

I can try:

Two requirements with whatever the solution is (#7715 (comment)):

  • Locally changed items from a receive-encrypted folder must never be sent to remotes.
  • Locally added items that are deleted again aren't a problem, thus shouldn't show as local changes in the web UI.

Status quo:

  • For receive-encrypted folders we filter out items with FlagLocalReceiveOnly when sending indexes. We keep that flag even if a file is deleted and only ever existed locally. For receive-only folders we remove the flag, because a deleted file that doesn't exist anywhere is not a concern, neither for sent indexes nor should it show up in the web UI as a locally changed item.
  • The web UI and Model.LocalChangedFolderFiles filter out deleted items with FlagLocalReceiveOnly for receive-encrypted folders.

Problem: Valid files that exist globally, but the user mistakenly deleted locally, aren't shown as missing in the UI and thus can't be recreated (by reverting).

Status PR:

Instead of removing the flag for deleted, locally changed files that only ever existed locally, like we do now for receive-only folders, we delete the item from the database.

  • The item isn't in the database, thus isn't going to be sent as index.
  • Same here: No need to ignore/filter anything towards the web UI, the item simply is gone.

How is it done:

Add a new method (s *FileSet) RemoveLocalItems(items []string).
On the db side, I re-use the code from updateLocalFiles that deals with removing the existing item from the db.
On the model/folder/scanner side, I extend the batch that holds scanned/changed items to be updated, to also hold items to be removed from the db (scanBatch). Same mechanism: Once the limit is reached (1000 items), RemoveLocalFiles is called. What previously was scanSubdirsBatchAppendFunc, is now (b *scanBatch) Update.

@calmh

calmh commented Jun 5, 2021

Copy link
Copy Markdown
Member

I need to think about this a little bit more, but I don't think we can just remove things from the database. Those entries will have taken up a sequence number, removing them and doing a meta recalculation would rewind the sequence number which is not great.

@imsodin

imsodin commented Jun 5, 2021

Copy link
Copy Markdown
Member Author

That's a good point: Recalculating metadata and not resetting delta indexes seems like a dangerous thing to do in general. Even today where there should be no way the sequence number decreases when recalculating metadata, I think it would be better to ensure it doesn't (or reset delta indexes).

@imsodin

imsodin commented Aug 11, 2021

Copy link
Copy Markdown
Member Author

Completely forgot about this PR - bump.

@st-review

Copy link
Copy Markdown

🤖 beep boop

I'm going to close this pull request as it has been idle for more than 90 days.

This is not a rejection, merely a removal from the list of active pull requests that is periodically reviewed by humans. The pull request can be reopened when there is new activity, and merged once any remaining issues are resolved.

@st-review st-review closed this Nov 10, 2021
@imsodin

imsodin commented Nov 10, 2021

Copy link
Copy Markdown
Member Author

Hmm, no. This is actually still a relevant bug-fix. Just unfortunately touching the db, i.e. an annoying one. @calmh If you'd prefer the alternative with the new flag (see below) instead of removing file-infos from db, I could create a PR for that (I'd still prefer the current approach, but very much understand the hesitance to touch/change this core/database part):

An alternative to this approach would be adding a new flag (e.g. FlagLocalReceiveEncryptedDeleted) and mark locally-changed, deleted items in receive-encrypted folders with that flag. This sidesteps the database changes, but instead of getting rid of useless file-infos, it keeps them with a new flag. That's why I'd prefer the db variant.

@imsodin imsodin reopened this Nov 10, 2021
@calmh

calmh commented Nov 10, 2021

Copy link
Copy Markdown
Member

I don't like either option as it's all intrusive, complicated and annoying. :) But thinking about it again I think it's fine to remove things from the database that should be unseen. At some point I want to revive my PR to remove old deleted items as well, in order to prevent infinite index growth, and that's similar.

The sequence number concern is there, but if it happens (which would only be if the removed item is the latest one) it should trigger the "out of sync with realize" path in delta indexes and force a full retransmission, fixing the issue.

@calmh

calmh commented Nov 10, 2021

Copy link
Copy Markdown
Member

So with that out of the way I think this is fine; is it good for review (still?) or needs something to revive?

@imsodin

imsodin commented Nov 10, 2021

Copy link
Copy Markdown
Member Author

The "sequence index going backwards on recalculation"-issue is even explicitly handled now: #7770

It was ready before, had a quick look over it now given it's been a long while, looks good and passes tests still after merging - ready for review.
Plus I very much agree with the following xD

I don't like either option as it's all intrusive, complicated and annoying. :)

@calmh
calmh enabled auto-merge (squash) November 10, 2021 08:46
@calmh
calmh merged commit 591e4d8 into syncthing:main Nov 10, 2021
@imsodin
imsodin deleted the all/encryption-deleted branch November 10, 2021 09:09
@calmh calmh added this to the v1.18.5 milestone Nov 10, 2021
calmh added a commit to calmh/syncthing that referenced this pull request Nov 22, 2021
* main: (32 commits)
  cmd/syncthing: Implement generate as a subcommand with optional API credential setting (fixes syncthing#8021) (syncthing#8043)
  lib/model: Correct "reverting folder" log entry
  lib/model: Correct handling of fakefs cache
  gui, lib: Fix tracking deleted locally-changed on encrypted (fixes syncthing#7715) (syncthing#7726)
  lib/config: Move the bcrypt password hashing to GUIConfiguration (syncthing#8028)
  lib/syncthing: Clean up / refactor LoadOrGenerateCertificate() utility function. (syncthing#8025)
  lib/api: http.Request.BasicAuth instead of custom code (syncthing#8039)
  Normalize CLI options to always use two dashes. (syncthing#8037)
  gui: Display identicons for discovered device IDs. (syncthing#8022)
  cmd/syncthing/cli: indexDumpSize doesn't need a heap (syncthing#8024)
  lib/model: Optimize jobQueue performance and memory use (syncthing#8023)
  lib/model: Limit the number of default hashers on Android (ref syncthing#2220)
  lib/model: Set mod. time after writing trailer in shortcut (ref syncthing#7992)
  lib/protocol: Simplify codeToError, errorToCode
  lib/protocol: Eliminate nativeModel on Unix
  gui: Add direct link to Ignore Patterns from folder panel (fixes syncthing#4293) (syncthing#7993)
  gui: Translate theme names in settings (syncthing#8006)
  lib/model: Pull when a new connection is established (fixes syncthing#8012) (syncthing#8013)
  gui, man, authors: Update docs, translations, and contributors
  gui, man, authors: Update docs, translations, and contributors
  ...
calmh added a commit to calmh/syncthing that referenced this pull request Nov 22, 2021
* main: (32 commits)
  cmd/syncthing: Implement generate as a subcommand with optional API credential setting (fixes syncthing#8021) (syncthing#8043)
  lib/model: Correct "reverting folder" log entry
  lib/model: Correct handling of fakefs cache
  gui, lib: Fix tracking deleted locally-changed on encrypted (fixes syncthing#7715) (syncthing#7726)
  lib/config: Move the bcrypt password hashing to GUIConfiguration (syncthing#8028)
  lib/syncthing: Clean up / refactor LoadOrGenerateCertificate() utility function. (syncthing#8025)
  lib/api: http.Request.BasicAuth instead of custom code (syncthing#8039)
  Normalize CLI options to always use two dashes. (syncthing#8037)
  gui: Display identicons for discovered device IDs. (syncthing#8022)
  cmd/syncthing/cli: indexDumpSize doesn't need a heap (syncthing#8024)
  lib/model: Optimize jobQueue performance and memory use (syncthing#8023)
  lib/model: Limit the number of default hashers on Android (ref syncthing#2220)
  lib/model: Set mod. time after writing trailer in shortcut (ref syncthing#7992)
  lib/protocol: Simplify codeToError, errorToCode
  lib/protocol: Eliminate nativeModel on Unix
  gui: Add direct link to Ignore Patterns from folder panel (fixes syncthing#4293) (syncthing#7993)
  gui: Translate theme names in settings (syncthing#8006)
  lib/model: Pull when a new connection is established (fixes syncthing#8012) (syncthing#8013)
  gui, man, authors: Update docs, translations, and contributors
  gui, man, authors: Update docs, translations, and contributors
  ...
@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 Mar 10, 2023
@syncthing syncthing locked and limited conversation to collaborators Mar 10, 2023
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.

3 participants