External File Versioning need Help

#!/bin/sh
set -eu
# The parameters we get from Syncthing
folderpath="$1"
filepath="$2"

# Where I want my versions stored
versionspath=~/Syncthing/Recycle
base=`basename "$folderpath"`

# First ensure the dir where we need to store the file exists
outpath=`dirname "$versionspath/$base/$filepath"`
mkdir -p "$outpath"

# Then move the file there
mv -f "$folderpath/$filepath" "$outpath"

its the doc example modified by me

I want catch only the deleted files and move them in a other folder. The modified files should do just sync to the newest version. Have no idea how to do this. need help

The versioner doesn’t know if the file is going to be deleted or replaced, unfortunately.

If we wanted to fix this I think we should deprecate the external versioner thing and add a more generic pre/post create/modify/delete hook system. So one might register a “pre-delete” hook to solve your use case, or a “post-*” hook to notify an external system of completed changes, etc. The current external versioner is the “pre-modify/delete” hook.

2 Likes

ok please do this cool stuff. :+1:

If it’s not a delete, there should be a temp file. If you check for that, you can detect if it’s a delete or not.

1 Like

How i can do this ? im a absolute beginner in bash scripting

calmh Or you could make a new option for the simple versioner(or all) with a costum path to set.

If you want this to happen it’s best to implement it yourself. We are not obliged to implement anything.

You can just create a symlink .stversions which points to somewhere on the same file system. Also, the trashcan versioner would be more suited for what you want. But none of the default versioners only handle deletes.

To check for a temp file in your script, this should do the trick:

...

if [ -f "${folderpath}/$(dirname "${filepath}")/.syncthing.$(basename "${filepath}").tmp" ]; then
    exit
fi

# First ensure ...
...

Though this won’t work for long file names (< 145 chars), as we use hashed bases file names than, to ensure compatibility with weird file systems.

2 Likes

i trying now this for me. but seems not to working

ln -s /home/pi/Syncthing/testtrash /home/pi/Syncthing/Test/.stversions

whats wrong ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.