Repository: syncthing/syncthing (language: go)

Issue:
Do not autoexpand tilde sign (~) to an absolute home directory path
I'm using Syncthing in a dualboot environment, sharing the same keys/config between operating systems. Everything works great. Paths to the shared directories are unified through symlinking in the home directory. However, the GUI doesn't allow entering the tilde `~` on adding folders, autoexpanding it to absolute form, thus requiring manual config editing. If entered manually, the tilde persists and creates no issues with Syncthing.

At some moment my config was changed (may be after some upgrade?) and the path was expanded to the absolute form on Windows, leading to silent creation of the directory on GNU/Linux and redownloading of the contents. I didn't notice it right away so was a bit annoyed.

It would be nice if the GUI didn't have this behaviour and left the `~` untouched.


Discussion / hints:
I would also like to have this feature but for another reason. Basically, it would make backing the config up and restoring it later easier, without any need to modify the paths even if the relevant user account has changed.

You can find the code responsible for the expansion by searching for `expandTilde` in https://github.com/syncthing/syncthing/blob/main/gui/default/syncthing/core/syncthingController.js.
It sounds strange that your Windows instance created the folder, if you shared the config and database between OSes. In that case, it should have noticed the folder marker missing and stopped the folder with an appropriate error message. So at least that shouldn't pose an immediate problem, but the other arguments still make a valid case for this enhancement.
> It sounds strange that your Windows instance created the folder, if you shared the config and database between OSes. In that case, it should have noticed the folder marker missing and stopped the folder with an appropriate error message. So at least that shouldn't pose an immediate problem, but the other arguments still make a valid case for this enhancement.

That's not exactly what happened. I suspect the path in the config was somehow changed while running Windows, and then Syncthing on GNU/Linux happily created a folder with a Windows absolute path for the name.
The point is, if an existing folder happens to point to a different path when Syncthing starts, it will stop with an error because the folder marker is missing at that path (or the path itself doesn't exist).  It should *not* create the folder path, that is only done when initially adding a folder to the config.  Are you certain that Syncthing did create the folder?  Can you reproduce this?  Then it might be a real bug, separate from this enhancement request.

Fix patch:
diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js
index a681eb8bc94..208cb5617f4 100755
--- a/gui/default/syncthing/core/syncthingController.js
+++ b/gui/default/syncthing/core/syncthingController.js
@@ -740,20 +740,12 @@ angular.module('syncthing.core')
         }
 
         function pathJoin(base, name) {
-            base = expandTilde(base);
             if (base[base.length - 1] !== $scope.system.pathSeparator) {
                 return base + $scope.system.pathSeparator + name;
             }
             return base + name;
         }
 
-        function expandTilde(path) {
-            if (path && path.trim().charAt(0) === '~') {
-                return $scope.system.tilde + path.trim().substring(1);
-            }
-            return path;
-        }
-
         function shouldSetDefaultFolderPath() {
             return $scope.config.defaults.folder.path && $scope.folderEditor.folderPath.$pristine && $scope.editingFolderNew();
         }
@@ -1988,7 +1980,7 @@ angular.module('syncthing.core')
             if (!newvalue) {
                 return;
             }
-            $scope.currentFolder.path = expandTilde(newvalue);
+            $scope.currentFolder.path = newvalue;
             $http.get(urlbase + '/system/browse', {
                 params: { current: newvalue }
             }).success(function (data) {


Test patch: