Description
What happened?
It is possible to pause/resume folders using the API like this:
curl -k -X PATCH -H “X-API-Key: foobar” ``https://localhost:8384/rest/config/folders/“xxxxx-xxxxx”`` -d ‘{ “paused”: true }’"
This works as expected, however those requests changes some other folder settings silently. It resets the “rescanIntervalS” for my folders to 3600 - no matter what I configured earlier. And the “Watch for Changes” setting is also reset to "enabled". It even resets those values if a "paused: false" is send to a activated folder, it then just resets the rescan interval to 1h. I have no idea where those 3600 are coming from because my default folder setting is another value and I configured some other value for this folder before using the API. This problem exists for a longer time but I now finally found the time to debug this a bit more.
Steps to reproduce
Set the “Full Rescan Interval (s)” using the Webinterface for one folder to 7200 or any other value, save changes. Verify that changes are written to .config/syncthing/config.xml (that does work for me). Then run curl -k -X PATCH -H “X-API-Key: foobar” ``https://localhost:8384/rest/config/folders/“xxxxx-xxxxx”`` -d ‘{ “paused”: true }’"
Check again the Webinterface: The folder is paused as expected but “Full Rescan Interval (s)” will be 1h/3600s again.
Known workaround
Thanks to the forum I verified that those resets are not happening if I use a command like syncthing cli config folders xxxxx-xxxxx paused set true instead of using the API
Syncthing version
2.0.8
Platform & operating system
Arch Linux
Browser version
Firefox 142.0.1
Activity
prashant933 commentedon Oct 1, 2025
Hi, I am new to syncthing and wanted to contribute to the project. Can I look into this issue? If yes, can you please assign this issue to me. Thanks
tomasz1986 commentedon Oct 1, 2025
We don't assign issues. If you want to contribute, please file a pull request. You may also want to read up https://github.com/syncthing/syncthing/blob/main/CONTRIBUTING.md#contributing-code before doing so.
prashant933 commentedon Oct 1, 2025
Sure. Will start working on it then. Thanks
prashant933 commentedon Oct 1, 2025
I found that the issue is related to the way we perform
json.unmarshal().folderconfiguration.gois having a functionUnmarshalJSON(data []byte)which is called whenever we try to unmarshal, but the problem is we performstructutil.SetDefaults(f)on the very first line.This causes default values defined in the struct to be populated.
An easy fix is to update SetDefaults() function to not populate any default value if the underlying struct already has some value corresponding to that field.
But I wanted to take suggestions if this looks ok or not. I don't have full context as to what might go wrong if I added this piece of code into SetDefaults(). Otherwise we need to find a way to restore original values after we had performed SetDefaults
AudriusButkevicius commentedon Oct 3, 2025
I don't think you can easily distinguish between "has no value" vs "has been explicitly set to not have a value, which is different from default".
Perhaps you could unmarshal the json into an empty folder somehow, without setting defaults, and then walk the fields that are set and only set them.
Or walk the json key by key and explicitly unmarshal values for those keys, into the struct fields.
Not sure.
nf-brentsaner commentedon Dec 4, 2025
You can, actually - use pointers for struct fields and
omitemptyoption on the json/xml struct tags. (It's not strictly necessary for JSON, as it has a native null representation that can be mapped to nil, but would be necessary for XML to prevent it from marshaling a zero-value on a nil field).nil ptr == "not present in original data" (e.g. XML from config or JSON from request), non-nil ptr pointing to the type's zero value == "explicitly set as zero value".
I haven't taken a look at the struct defs, so this might be a significant refactoring if pointers aren't already being used. However, since you maintain your own defaults setter, this would allow you to check for an 'allowzero' option in the
defaulttag that applies to ptr fields (ignored otherwise) that does not set a default on a nnon-nil-but-zero-value vs. nil field value (seereflect.Value.IsNil(),reflect.Value.IsValid(),reflect.Value.IsZero()) that dictates how your defaults setter handles nil fields.fix(config): remove extraneous defaults setting while unmarshalling f…
fix(container): update image ghcr.io/syncthing/syncthing (2.1.1 ➔ 2.1…
fix(container): update image ghcr.io/syncthing/syncthing (2.1.1 ➔ 2.1…
fix(container): update image ghcr.io/syncthing/syncthing (2.1.1 ➔ 2.1…