Feature Request - Sync Creation Times/Dates


#1

Hi I cannot find if this is the right place for this, but I would like Syncthing to synchronize the File and Directory Creation Time. Is there a chance to have this one day? (and is there a Feature Request somewhere with a voting system?) Many Thanks Eric


Syncthing for macOS
(Jakob Borg) #2

There is typically no separate creation date stored that I’m aware of. Modification times of directories we do not sync, because it’s annoying. Essentially, syncing a file in a directory will update the modification of the directory, so we’d need to recurse upwards resetting modification times after each change. We did this at one point, but it was a fair amount of work and not 100% reliable.


#3

Thanks for your reply Jakob.

I have found on stackexchange.com: “Linux doesn’t keep track of the creation time since it is not required by POSIX. However, Mac OS X does with the HFS filesystem — look under “birth time” in stat”

As you can guess… I am working on mac. Once newly synchronised, all the files are dated “today”. I understand for directories, but for files, it’s a pity that the creation dates are not set same as the original ones. Would it be possible that this is implemented for Mac?

Thanks again Eric


(Jakob Borg) #4

Cool, I learned something new about Mac :slight_smile:

No, this is vanishingly unlikely that we would implement, given that we mostly stick the common denominator of all supported OS:es.


(Audrius Butkevicius) #5

I don’t see why we could not support it on platforms that support it, but I don’t think Go exposes btime, nor do I see anyone entertained enough to make this happen.


(Hugo Buddel) #6

Recently started using Syncthing (replacing Dropbox), and all directories on the ‘second’ machine have as date the moment Syncthing first synced. I’d like the dates on the second machine to be the same as on the first machine.

I often use ls -ltr, e.g. to get to the projects I’ve last worked on. Perhaps not the best workflow, but I’m used to it. (Then again, why do directories have dates if we’re not supposed to use them?) Perhaps I can approximate the original date by writing a script that gives each directory the date of the latest modified file in the directory.

It seems not necessary to do anything recursive to achieve the desired behavior. Just copy over the date when syncing directories for the first time, and then keeping them in sync when they change. About the date to use, I’d say the date that window managers of the OS show by default. What users see is what matters most, irrespective of whether this is atime, btime, ctime or whatever.


(Hugo Buddel) #7

Running this bash command in my Sync directory was good enough for me:

find . -type d ! -empty | tac | while read -r dir
do
touch -t $(ls -pAl --time-style="+%Y%m%d%H%M.%S" "$dir" | tail -n +2  | awk '{print $6}' | sort -n | tail -n 1) "$dir"
done

It traverses all directories (find . -type d ! -empty), deepest directories first (tac). It works with directories with spaces (while read -r). Then it lists the contents in those directories (ls -pAl) with a timestamp that touch accepts (--time-style="+%Y%m%d%H%M.%S"), removes the ‘total’ line (tail -n +2), selects only the timestamps (awk '{print $6}'), sorts them numerically (sort -n), picks the latest one (tail -n 1) and sets the directory time to that (touch -t). It doesn’t as desired when there are empty directories.

The directory times on my second machine are not the same as on my first machine, but good enough.