Folder>path subfield in config.xml to support multi booting devices

There are several previous topics about how to properly set up Syncthing in devices with at least two OS [1] [2] [3] [4] [5]. The configuration files to care about are those described at docs.syncthing.net/users/config.

The most-simple solution, which allows to have different repositories configured for each OS, is to run completely independent setups for each OS (different -home=<dir>) [1]. However, renaming folders can cause errors or duplicates [4] (#3). On top of that, to avoid conflicts, changes should be properly propagated before switching to another OS [4] (#4).

Conflicts may be mitigated keeping data in the same place and using symlinks to share the index [4] (#4). In this scenario, the same certificates could be used, so that the same device ID is shown in either OS [1]. But, doing so can produce conflicts if not strictly identical repos are configured [2]. To prevent it, any change of configuration must be edited manually in the other OS.

Another popular solution is to share the -home=<dir> and keep data in the same place, using symlinks to map the path attribute of folder fields in config.xml [1] [3]. Still, this solution requires the user to remember the value of the attribute to create the symlinks in all the OS.

As an exercise to try Go, I’ve written a basic program which:

  • Reads config.xml

  • Uses user.Current() to get Uid, Gid, Username, Name and HomeDir, and computes an MD5 appending all of them (current_hash).

  • For each folder, checks if a subfield <path hash=""></path> exists and if the content of the attribute matches current_hash.

    • If they match, the path attribute of <folder> is replaced with the value of the matching <path> subfield.
    • Else, the user is required to locate the repo or keep the actual value.
  • The modified structure is written to config.xml

Since Syncthing ignores those aditional subfields (testconfig.xml), this tiny program can be run before executing it, and no conflicts are produced.


Now I’d like to:

  • When the location of a repo is changed through the GUI, update: the attribute of <folder path="HERE"> and the content of <path hash="current_hash">"HERE"</path>. I suppose I’ll have to figure out how to read ConfigSaved events from the API (JSON). Is this correct?
  • Replace func askUser with a box in the GUI. When launched, I’d like Syncthing to stop the folders which require the user to locate them for the current OS. After the GUI is launched, the user would provide the required input, and those folders would be started.

I’ve cloned and successfully built Syncthing. I’ve seen that the structures in lib/config/ (config.go, folderconfiguration.go, etc.) are pretty much the same that I’ve used. But I don’t know where to start from. Is there any documentation about how syncthing is structured?

You cannot change the folders path. The only way you can change it is by removing it, and readding it.

As for the structure, the best way to understand it, is to browse the code.

http://docs.syncthing.net/dev/intro.html is the official start page, contains some of that info.