You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A new folder's relative path is resolved against the working directory, not the default folder path #10937
A folder path that isn't absolute and doesn't start with ~ is resolved against the working directory of Syncthing. That directory depends on how Syncthing was started, it can even be / for a systemd system service. So an API client has no simple way to put a new folder under the default folder path:
A relative path lands relative to the process's working directory.
Omitting the path makes the folder use the default folder path itself (POST /rest/config/folders decodes the request over a copy of the folder defaults), so every folder added that way shares one directory.
Joining the path client-side, as the GUI does, works, but the client can't see whether that directory already exists on the device.
Steps to reproduce (v2.1.7)
Start the syncthing server with CWD = /home/syncthing
Set the folder defaults' path to e.g. /mnt/sync.
POST /rest/config/folders with {"id": "abcde-12345", "path": "foo/bar"}.
The folder's directory is /home/syncthing/foo/bar, not /mnt/sync/foo/bar.
Suggestion
When a folder is created through the API, resolve a relative path against the default folder path and store the absolute result. If no path is given, use the same algorithm that auto-accept uses. Return 409 Conflict if that resolved path already exists and isn't an empty directory (and possibly if it is part of another folder, but I believe there is some experimental support for folder within a folder). Absolute paths, ~ paths and existing folders would be unaffected (although 409 could be consiedered here too if they already exist and are non-empty)
I'm not fluent in go, so rather than implement this with AI, i'd leave it to you.
Folder path has always been relative to the current directory. I don't think it's a bug, and changing the current state of things is rather a feature request.
Is this desirable though? There are legitimate cases for using such relative paths (e.g. in portable Syncthing installations, or when sharing the same config between multiple operating systems). If you don't want the path to be relative, you can just specify a full path or utilise ~ (also when using the API, as far as I'm aware...).
I fully agree with @tomasz1986. The described behavior is intentional and useful. The fact that there is a "default folder path" at all is mostly for technical reasons, but we do use it for the auto-accept feature. You should not expect it to mean anything special for manual folder addition though. If you want to use it as a basis for scripted folder addition via the API, then get it from the API and derive your absolute path from it.
Thanks for the replies. The issue was closed within about a day, a few hours after the last comment and before I could reply. That felt dismissive, and as an outside contributor it left me shut out of the discussion. I'd appreciate it being reopened as I'd like to push back, but I didn't get the chance to before this was closed.
I don't believe the portable case and this proposal conflict. A fresh config has an empty default folder path (). So: if it's empty, keep resolving relative paths against the working directory, exactly as today - portable installs and shared configs don't set it and see no change. If it's set, that's the admin already saying where they expect new folders to go, and a relative path should resolve against it. Only someone who set a default folder path and relies on relative paths landing in the working directory would notice.
Requiring an absolute path as a workaround couples API clients to the server's filesystem. To put a folder under the default folder path, a (remote) client has to read that path, know the server's layout and path conventions, and join the path itself - for a machine it may never have seen. When Syncthing is managed remotely over the API, the server is (and should be the only) one that knows its disk, and it already makes exactly this decision for auto-accept.
Omitting path can expose other folders to a device they were never shared with. POST /rest/config/folders decodes over a copy of the folder defaults. With an empty default, a folder without a path is refused (folder has empty path - as a 500, though it's a client error). With a default set, it's accepted silently, and the folder's root is the directory auto-accepted folders are created in (and NOT the CWD of the process, although relative paths are resolved against that currently). Tested with AI on v2.1.7 with three devices: P shared alpha and beta with S only, and S auto-accepted both into its default folder path. S then added a folder with no path, shared with R. R received every file of alpha and beta - polluting the original intention of creating an empty share. Could a new folder without a path be refused when a default is set too - with a 400 - or get the / auto-accept would give it?
There's no way to say "only if that directory is new or empty." /rest/system/browse lists directories only, so a client can't tell an empty directory from one full of unrelated files before adopting it.
Details of the AI-driven test:
syncthing v2.1.7 "Hafnium Hornet" (go1.27.3 linux-amd64), three instances on one machine, connected over 127.0.0.1 with global and local discovery, relays and NAT traversal off. Each starts from syncthing generate, so everything not listed below is the default config.
- S: default folder path set to S-data; auto-accepts folders from P.
- P: shares alpha and beta with S only (two files each, one in a subdirectory).
- R: knows S only.
Then:
1. S auto-accepts alpha and beta into S-data/alpha and S-data/beta.
2. S gets POST /rest/config/folders with {"id": "outer-00000", "label": "outer", "devices": [{"deviceID": "<R>"}]}, with no path.
3. R adds outer-00000 at a directory of its own, shared with S.
4. R writes a file into its copy of alpha.
Output:
1. P shares alpha and beta with S only; S auto-accepts them
S: alpha-00000 at /tmp/st/S-data/alpha
S: beta-00000 at /tmp/st/S-data/beta
2. S adds folder outer-00000 with no path, shared with R
POST /rest/config/folders -> 200
outer-00000's path on S: /tmp/st/S-data
3. R accepts outer-00000 into a directory of its own
outer-00000 on S: {"state":"idle","globalFiles":6,"globalDirectories":6}
errors on S: []
files R received:
./alpha/one.txt
./alpha/.stfolder/syncthing-folder-66cfcc.txt
./alpha/sub/two.txt
./beta/one.txt
./beta/.stfolder/syncthing-folder-27d294.txt
./beta/sub/two.txt
./.stfolder/syncthing-folder-d47ca0.txt
alpha and beta are shared on P with: {"alpha-00000":["3YJZI5O","5WGPUUL"],"beta-00000":["3YJZI5O","5WGPUUL"]}
(P is 5WGPUUL, S is 3YJZI5O, R is BFKXLSV)
4. R writes a file into its copy of alpha
P's alpha/from-r.txt: written on R
P's alpha/from-r.txt: written on R
So the folder created without a path has S's whole default folder path as its root: alpha's and beta's files, .stfolder markers included, are its contents, with no error or warning. R receives them although P shares those folders with S only. It also works the other way: a file R wrote into its copy reached P's alpha (it took about 20 seconds in an earlier run).
<details><summary>Script (run as <code>nopath-repro.sh <empty directory></code>; needs syncthing, curl, jq)</summary>
#!/bin/bash
# Three Syncthing instances on 127.0.0.1 (no discovery, relays or NAT):
# P shares folders alpha and beta with S only;
# S auto-accepts folders from P, into its default folder path;
# S then adds a folder with no "path" through the REST API, shared with R.
# Usage: nopath-repro.sh <empty working directory>
set -euo pipefail
T=$(realpath "$1"); mkdir -p "$T"
declare -A GUI=([S]=18441 [P]=18442 [R]=18443) SYNC=([S]=23041 [P]=23042 [R]=23043) ID KEY
start() { # name
local home=$T/$1
syncthing generate --home="$home" --no-port-probing >/dev/null
sed -i -e "s|127.0.0.1:8384|127.0.0.1:${GUI[$1]}|" \
-e 's|<listenAddress>[^<]*</listenAddress>||g' \
-e "s|<options>|<options><listenAddress>tcp://127.0.0.1:${SYNC[$1]}</listenAddress>|" \
-e 's|<globalAnnounceEnabled>true|<globalAnnounceEnabled>false|' \
-e 's|<localAnnounceEnabled>true|<localAnnounceEnabled>false|' \
-e 's|<relaysEnabled>true|<relaysEnabled>false|; s|<natEnabled>true|<natEnabled>false|' \
"$home/config.xml"
mkdir -p "$T/$1-data"
(cd "$T" && setsid -f syncthing serve --home="$home" --no-browser --no-upgrade >"$home/log.txt" 2>&1)
}
cli() { local n=$1; shift; syncthing cli --home="$T/$n" "$@"; }
api() { local n=$1 path=$2; shift 2; curl -s -H "X-API-Key: ${KEY[$n]}" "$@" "http://127.0.0.1:${GUI[$n]}$path"; }
link() { cli "$1" config devices add --device-id "${ID[$2]}" --name "$2" --addresses "tcp://127.0.0.1:${SYNC[$2]}"; }
wait_for() { for _ in $(seq 60); do [ -e "$1" ] && return; sleep 1; done; echo "timed out waiting for $1"; exit 1; }
start S; start P; start R
sleep 7
for n in S P R; do ID[$n]=$(cli $n show system | jq -r .myID); KEY[$n]=$(cli $n config gui apikey get); done
cli S config defaults folder path set "$T/S-data"
link S P; link P S; link S R; link R S
cli S config devices "${ID[P]}" auto-accept-folders set true
echo "1. P shares alpha and beta with S only; S auto-accepts them"
for f in alpha beta; do
mkdir -p "$T/P-data/$f/sub"
echo "$f file 1" > "$T/P-data/$f/one.txt"
echo "$f file 2" > "$T/P-data/$f/sub/two.txt"
cli P config folders add --id "$f-00000" --label "$f" --path "$T/P-data/$f"
cli P config folders "$f-00000" devices add --device-id "${ID[S]}"
done
wait_for "$T/S-data/alpha/sub/two.txt"; wait_for "$T/S-data/beta/sub/two.txt"
api S /rest/config/folders | jq -r '.[] | " S: \(.id) at \(.path)"'
echo "2. S adds folder outer-00000 with no path, shared with R"
api S /rest/config/folders -X POST -H 'Content-Type: application/json' \
-d "{\"id\": \"outer-00000\", \"label\": \"outer\", \"devices\": [{\"deviceID\": \"${ID[R]}\"}]}" \
-o /dev/null -w " POST /rest/config/folders -> %{http_code}\n"
echo " outer-00000's path on S: $(api S /rest/config/folders/outer-00000 | jq -r .path)"
echo "3. R accepts outer-00000 into a directory of its own"
cli R config folders add --id outer-00000 --label outer --path "$T/R-data/outer"
cli R config folders outer-00000 devices add --device-id "${ID[S]}"
wait_for "$T/R-data/outer/beta/sub/two.txt"; sleep 2
echo " outer-00000 on S: $(api S '/rest/db/status?folder=outer-00000' | jq -c '{state, globalFiles, globalDirectories}')"
echo " errors on S: $(api S '/rest/folder/errors?folder=outer-00000' | jq -c '.errors // []')"
echo " files R received:"; (cd "$T/R-data/outer" && find . -type f | sort | sed 's/^/ /')
echo " alpha and beta are shared on P with: $(api P /rest/config/folders | jq -c '[.[] | {(.id): [.devices[].deviceID[0:7]]}] | add')"
echo " (P is ${ID[P]:0:7}, S is ${ID[S]:0:7}, R is ${ID[R]:0:7})"
echo "4. R writes a file into its copy of alpha"
echo "written on R" > "$T/R-data/outer/alpha/from-r.txt"
wait_for "$T/P-data/alpha/from-r.txt"
echo " P's alpha/from-r.txt: $(cat "$T/P-data/alpha/from-r.txt")"
pkill -f "syncthing serve --home=$T/"
</details>
Portable use case or not, changing this today would be a breaking API change as it changes the meaning of posting a non-absolute path, and with over a million users I can assure you that there are some out there depending on every detail of the current contract, documented or implied. We are not changing this at this stage of development.
Fair enough - although I still believe it should be a documented caveat. And possibly add (an optional) parameter that allows specifying where relative paths are relative to.
In ddition point 3 is a serious bug, syncthing behaves differently if the default path is set, and for an empty path it becomes the default path, not CWD.
Activity
tomasz1986 commentedon Oct 24, 2026
Folder path has always been relative to the current directory. I don't think it's a bug, and changing the current state of things is rather a feature request.
Is this desirable though? There are legitimate cases for using such relative paths (e.g. in portable Syncthing installations, or when sharing the same config between multiple operating systems). If you don't want the path to be relative, you can just specify a full path or utilise
~(also when using the API, as far as I'm aware...).docs: FORK.md branch-model simplification, PATCHES.md table repairs +…
docs: record syncthing#10909 as the fork's founding issue; correct ga…
docs: FORK.md branch-model simplification, PATCHES.md table repairs +…
docs: record syncthing#10909 as the fork's founding issue; correct ga…
acolomb commentedon Oct 24, 2026
I fully agree with @tomasz1986. The described behavior is intentional and useful. The fact that there is a "default folder path" at all is mostly for technical reasons, but we do use it for the auto-accept feature. You should not expect it to mean anything special for manual folder addition though. If you want to use it as a basis for scripted folder addition via the API, then get it from the API and derive your absolute path from it.
axos88 commentedon Oct 26, 2026
Thanks for the replies. The issue was closed within about a day, a few hours after the last comment and before I could reply. That felt dismissive, and as an outside contributor it left me shut out of the discussion. I'd appreciate it being reopened as I'd like to push back, but I didn't get the chance to before this was closed.
I don't believe the portable case and this proposal conflict. A fresh config has an empty default folder path (). So: if it's empty, keep resolving relative paths against the working directory, exactly as today - portable installs and shared configs don't set it and see no change. If it's set, that's the admin already saying where they expect new folders to go, and a relative path should resolve against it. Only someone who set a default folder path and relies on relative paths landing in the working directory would notice.
Requiring an absolute path as a workaround couples API clients to the server's filesystem. To put a folder under the default folder path, a (remote) client has to read that path, know the server's layout and path conventions, and join the path itself - for a machine it may never have seen. When Syncthing is managed remotely over the API, the server is (and should be the only) one that knows its disk, and it already makes exactly this decision for auto-accept.
Omitting path can expose other folders to a device they were never shared with. POST /rest/config/folders decodes over a copy of the folder defaults. With an empty default, a folder without a path is refused (folder has empty path - as a 500, though it's a client error). With a default set, it's accepted silently, and the folder's root is the directory auto-accepted folders are created in (and NOT the CWD of the process, although relative paths are resolved against that currently). Tested with AI on v2.1.7 with three devices: P shared alpha and beta with S only, and S auto-accepted both into its default folder path. S then added a folder with no path, shared with R. R received every file of alpha and beta - polluting the original intention of creating an empty share. Could a new folder without a path be refused when a default is set too - with a 400 - or get the / auto-accept would give it?
There's no way to say "only if that directory is new or empty." /rest/system/browse lists directories only, so a client can't tell an empty directory from one full of unrelated files before adopting it.
Details of the AI-driven test:
axos88 commentedon Oct 26, 2026
@calmh @acolomb ^
calmh commentedon Oct 26, 2026
Portable use case or not, changing this today would be a breaking API change as it changes the meaning of posting a non-absolute path, and with over a million users I can assure you that there are some out there depending on every detail of the current contract, documented or implied. We are not changing this at this stage of development.
axos88 commentedon Oct 26, 2026
Fair enough - although I still believe it should be a documented caveat. And possibly add (an optional) parameter that allows specifying where relative paths are relative to.
In ddition point 3 is a serious bug, syncthing behaves differently if the default path is set, and for an empty path it becomes the default path, not CWD.
Release the binaries themselves, not archives
calmh commentedon Oct 26, 2026
I'm not opposing documenting it, and indeed you can specify where relative paths are relative to -- by changing cwd before starting Syncthing. :)
Will file a separate issue for the bug you noted.
docs: FORK.md branch-model simplification, PATCHES.md table repairs +…
docs: record syncthing#10909 as the fork's founding issue; correct ga…
docs: FORK.md branch-model simplification, PATCHES.md table repairs +…
docs: record syncthing#10909 as the fork's founding issue; correct ga…