0
Answered

Nextcloud sync working - exept when file is in subfolder

Georg L 1 year ago updated 3 weeks ago 3

Hello from Germany,

I have a small problem with the Nextcloud desktop app, I hope somebody can help me with that : )

User in this example is "xyz".

1) Inside the user-home-folder [ /media/smb/xyz ] for user 'xyz' I have mounted a smb share from FreeNAS.

Everything is working, I can access, delete, everything.

2) If I create/copy/delete a file in the home root dir [ /media/smb/xyz/file1 ] from my windows machine, the file is synced to my Notebook via Nextcloud Desktop app.
3) If I create a file inside a subfolder [ /media/smb/xyz/folder2/file2 ] it wont sync.
4) I can force file2 to sync, by logging into webgui, open "file2" and save it.

_______________________________________________________________________________________________

### OVERVIEW ###

# Home-user-folder for user "xyz"

/media/smb/xyz

# FreeNAS share mounted via cifs-util with emulated permissions for user "www-data" (including subfolders and files)

/media/smb/xyz/folder2/....

/media/smb/xyz/file1/....

/media/smb/xyz/folder12/....

and so on.

# Sync problem
I copy "file1" to ~/ of smb share

/media/smb/xyz/file1

--> Sync works (same with folders)


I copy "file2" to ~/folder2 of smb share

/media/smb/xyz/folder2/file2

--> Sync doesnt work
I log into web gui, go into "folder2" open "file2" and save it. File is syncing.
_______________________________________________________________________________________________

It seems, FileRun (or nextcloud ???) is only looking on the first layer [ /media/smb/xyz/ ] for syncing.
And not on sublayers [ /media/smb/xyz/folder/folder/file ].

I described it as good as i can ... hopefully.

Greetings
Georg

Answered

It is a limitation of the Nextcloud sync system, related to the fact that if you create files from outside FileRun/Nextcloud and not "touch" the file's parent folders, the client apps will not detect the change. The change is detected by the folders modification timestamp.

When you make a change via FileRun, the entire folder structure gets the timestamp updated.
So for a file like "/media/smb/xyz/folder2/file2" you would have to do this:

touch -m /media/smb/xyz/folder2
touch -m /media/smb/xyz
touch -m /media/smb

Note that while it can work just by touching "/media/smb/xyz", if a Nextcloud client app is configured to only sync "/media/smb/xyz/folder2", it won't look for the timestamp of the parent folder, so no sync would get triggered in that case.

We are also facing this problem. Do you have any advice on how to best address it?

Should we use a custom event script or solve it outside of filerun?

Thank you in advance.

Here is a script that can help. It touches the parent folders and ensures file sync can find any changes in sub folders.

filepath=/path/to/root

inotifywait -rme modify,create,delete,move --format '%w%f' --exclude '.*\.filerun\.versioning.*' $filepath |
while read dir; do
parent="$(dirname -- "$dir")"
if (( ${#parent} == ${#touchparent} )); then continue; fi
if (( ${#parent} == ${#filepath} )); then continue; fi
touchparent=$parent
echo "Touching $touchparent"
touch -m "$touchparent"
done