Synchronizing folders relative to sync.ffs_gui

Get help for specific problems
Posts: 4
Joined: 1 Aug 2023

CarstenF

Edit: let me ask my question differently.

Hi,
I have a USB-Stick on my keychain with several folders that I want to sync to a SFTP for mostly backup purposes.
So I placed a sync.ffs_gui in each folder.
In that ffs_gui I wrote "./" as a relative path that should point to the folder where the file is in (after double-click-opening).
Under Windows this works.
Under Linux Mint it resolves to the home folder.

Is this a bug or should I use a different path so it works under both Linux and Windows?
Posts: 4
Joined: 1 Aug 2023

CarstenF

I found a workaround.
Create a file like sync.sh, make it executable and in it you write "freefilesync sync.ffs_gui".
Then it is launching with the correct working directory.
I tried to fix /usr/share/applications/FreeFileSync.desktop but there is something wrong not related to FFS.
Ther are some whacky solutions on the internet but most fail if theres a space in the path and they cause all sorts of other problems.
User avatar
Site Admin
Posts: 7211
Joined: 9 Dec 2007

Zenju

Indeed, the working directory is not set on Linux the same way as it is done on Windows when you double-click on a ffs_gui file.
I tried to fix /usr/share/applications/FreeFileSync.desktop but there is something wrong not related to FFS. CarstenF, 03 Aug 2023, 11:59
The following might be a workaround for FreeFileSync.desktop:
Exec=/bin/bash -c 'FFS_ARG="%f"; cd "$(dirname "$FFS_ARG")"; "/opt/FreeFileSync/FreeFileSync" "$FFS_ARG"'
Update: Apparently this doesn't work when there are spaces in the file paths.
Posts: 4
Joined: 1 Aug 2023

CarstenF

I was at that point too, this does not work if a space is in the path.
User avatar
Site Admin
Posts: 7211
Joined: 9 Dec 2007

Zenju

The desktop file's "Exec" is parsed once before the command is executed, so we need some escaping. The following version should do the trick:
Exec=/bin/sh -c "filePath=%f; cd \"$(dirname \"$filePath\")\";  /opt/FreeFileSync/FreeFileSync \"$filePath\""
Some implementation details about Exec I found out:
either %f or %F is replaced, and exactly once
• %f is replaced by file path with single quotes if path contains spaces. (This is why the Exec example above must start with double quotes)
• %F is replaced by a list of single-quoted paths if spaces occur inside them.
Posts: 4
Joined: 1 Aug 2023

CarstenF

YES, that works.
Thank you.
I'll make
Exec=/bin/sh -c "filePath=%f; cd \"$(dirname \"$filePath\")\";  /opt/FreeFileSync/FreeFileSync \"$filePath\"; rm ~/.config/FreeFileSync/LastRun.ffs_gui"
of it, because if I open FFS via desktop shortcut by accident I might overwrite my backup with my home folder data. Would be nice if there was an option not to save that file automatically.
User avatar
Site Admin
Posts: 7211
Joined: 9 Dec 2007

Zenju

Here's an improved version using bash arrays. In addition to single file path arguments it works with:
• multiple path arguments
• zero arguments
Exec=/bin/bash -c "paths=(%F); cd \"\$(dirname \"\${paths[0]}\")\"; /opt/FreeFileSync/FreeFileSync \"\${paths[@]}\" "
Example: Exec will make bash execute a command like the following:
paths=('folder/spaced file.txt'); cd "$(dirname "${paths[0]}")"; /opt/FreeFileSync/FreeFileSync "${paths[@]}"
Update 2023-09-16: Apparently the syntax does not work on all Linux systems, e.g. it fails with a syntax error on WSL2 and on Kubuntu: viewtopic.php?t=10666