obsidian-livesync icon indicating copy to clipboard operation
obsidian-livesync copied to clipboard

Can HiddenFileSync update the logic?

Open zcr268 opened this issue 2 years ago • 2 comments

Thanks for your sync plugin, it helped me a lot

But the synchronization logic regarding hidden files looks confusing

I noticed the code

CmdHiddenFileSync.ts#L212

Here you need to pass in the direction of synchronization when synchronizing hidden files

However, after setting the synchronization period and on the synchronization command, the CmdSetupLiveSync.ts#L224:mode of hidden file synchronization is not used at all

For example: CmdHiddenFileSync.ts#L16 CmdHiddenFileSync.ts#L35 Here I intuitively think that it should be synchronized based on mode, but mode is not stored in the plugin. I don't understand that this is deliberately designed? Can you explain why?

Forgive me for not being able to write English very well, but that's because it's translated using translation software

zcr268 avatar Jul 19 '23 08:07 zcr268

Thank you for asking me and reading the rather complicated code! I have written the answer, but it is a bit long. Please feel free to ask me more.

The mode you have pointed out is configuring which of Hidden File Sync or Customisation sync (or neither) is enabled. Therefore, if we have answered to use Hidden File Sync (The mode is FETCH, OVERWRITE or MERGE), it will be saved as syncInternalFiles=true. Then CmdHiddenFileSync will be enabled.

The argument direction of syncInternalFilesAndDatabase means below:

  • push - update (or store, delete) the database by storage content, if storage content is new.
  • pushForce - same as push but not care about is new.
  • pull - apply (or create, delete) database content to the storage, if database content is new.
  • pullForce - same as pull but not care about is new.
  • safe - update or store the database by storage content if it is new, otherwise, apply or create database content to the storage. No deleting.

In CmdHiddenFileSync, periodicInternalFileScanProcessor is responsible to detect changes on the storage and to push them. beforeReplicate is also the same. In other cases, e.g., responding to the synchronised new entries is performed on procInternalFile which is called from the main. In that method, pull for specific files has been performed. In addition to that, if not configured disabling the use of internal API, when a file has been changed on the vault, watchVaultRawEventsAsync will be called and it will store the file.

vrtmrz avatar Jul 20 '23 10:07 vrtmrz

The logic of the code is indeed what you said, and that's why I'm confused. when i select FETCH on the ui of the settings page, i thought it would be FETCH for every future sync, but it wasn't

zcr268 avatar Jul 21 '23 05:07 zcr268