Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Save the modification time of files #462

PJaros opened this Issue Dec 2, 2011 · 13 comments


None yet
7 participants

PJaros commented Dec 2, 2011

This is based on experience with my tests using Ubuntu 10.10 + 11.10 with SparkleShare 0.4.

My goal using SparkleShare is to use it to sync my Photos across my LAN-Connected Computers. Uploading and syncing works like a charm. The trouble is that the modification time of the original uploaded file isn't saved and that all synced computers will get the file with the modification time updated to the moment the data is synced.

The modification time is very important to in order to organize my files. I've looked into the git documentation and found no way to configure git to retain the modification time. So what I would want to propose is to save the modification time into a separate file (like ".gitdate") and to apply it while synchronizing.

neteler commented Dec 30, 2011

It would be pretty cool/important to keep the timestamps. Saving the modification time into a separate file (like ".gitdate") and to apply it while synchronizing sounds like a nice idea to me.

Axel19 commented Mar 9, 2012

Creating an extra file is not necessary.
It would be great if this would be implemented into Sparkleshare by default.
In the meanwhile one can manually run a script to get the info out of the git log for every file in a directory like this (warning quick and dirty) , also works for directories:

 for FILE in *; do touch "$FILE" -d "`git log -1 --date=local "$FILE"|grep Date|awk -FDate: '{print $2}'`";done 

It's possible that one could implement this via some hook for the whole repository, but i'm not that familiar with git so far.
Anyway this feature would be great.


hbons commented Mar 10, 2012

@Axel19 that's a good idea. is there way to get all the paths with date info in one go without spawning a git process for each file?

Axel19 commented Mar 10, 2012

Well, one could parse the whole git log and extract the info for each file.
Of course i just realized the problem doing it this way is you still only get the added or modified date from the repo not the original file date. I'm trying to find a way doing this via git.

Axel19 commented Mar 10, 2012

Well it seems to be the nature of the beast to usually not change the modification times on files.
By doing so git might run into problems, though i think it's fine when doing it only for added files and on machines running NTP.
Anyway i implemented 2 hooks
The first one changes the commit msg in case a file is added to the repo and adds the modification time.
The second one runs after the commit and checks in case a file is added if the modification time equals the one in the commit msg, if not the time of the file is changed.
Maybe someone can test this a bit to see if any problems occur. I tried to be careful with the regex expressions.
It would be nice if the commit msg in SparkleShare by default would add the modification date to the commit msg , that way one could always retrieve the information from there, no extra file required.
UPDATE the script worked only for single commits, new ones below


# Change the commit msg to include the original modification time of the file in case a file is added to the repo
while read line
        STATUS=`echo "$line" |awk '{print $1}' `
        if [ "$STATUS" == "+" ] ; then
                MODT=`echo "$line" |sed 's/+\ //'|sed 's/\‘\(.*\)\’/\1/' `
                MODT2=`stat -c %Y "$MODT"|awk '{print strftime("%c",$1)}'`
                #MSG=`tr -d '\n' < $MSGLOC`
                #echo "$MSG :$MODT2" > $1
                sed -i "${LINENR}s/\(.*\)/\1 :$MODT2/" $MSGLOC
done  <$1


# Check if the modification date for added files is correct
CMSG=`git log -1 HEAD|tail +5`
for line in $CMSG
        ACTION=`echo $line|awk  '{printf $1}'`
        if [ "$ACTION" == "+" ] ; then
                FILE=`echo $line|sed 's/.*\‘\(.*\)\’.*/\1/' `
                MODT=`echo $line|sed 's/.*\’\ :\(.*\)/\1/' `
                MODT2=`stat -c %Y "$FILE"|awk '{print strftime("%c",$1)}'`
                if [ "$MODT" != "$MODT2" ]; then
                        echo "setting original modification date for file $FILE"
                        touch -d "$MODT" "$FILE"

wsw70 commented Mar 20, 2012

This problem is also present in a Windows <-> Linux <-> Windows scenario and Alex's hack will not work on Windows


hbons commented Apr 18, 2012

Files have two timestamps, one for the creation time, and on for the modification time. Do both of these get erased by git?

Axel19 commented Apr 29, 2012

Well, the creation time by default is always the creation time of a file in the local fs . There should be no reason changing the ctime. The mtime however is whats usually quite useful when handling collections of media files, documents etc.
I found this project for git including some example hooks to store even xattr for each file in a single file db .
Out of the box one could create a metadb file for a repository and use it so save the modification date of each file.
This would of course only work for Linux and probably OSX .
Creating a single file for a repository or maybe better on a directory basis like suggested by neteler would be probably the right way to go.


hbons commented Jun 11, 2012

Could possibly be done with git-bin

ginkel commented Aug 5, 2012

It seems that gibak could also serve as the basis of a solution (although the project seems somewhat orphaned).

gitp Scheme script was made to be wrapper around git executable. Obviously that would do little help for GUI applications calling git or using LibGit[2]
Interesting point is making hash/timestamp table so that every file revision would be eventually in it.

http://stackoverflow.com/questions/1964470 This script sets files timestamps to commit date. Which is not it, but might be kind of start.


hbons commented Dec 21, 2012

i've added this feature to git-bin: hbons/git-bin@422877f, so this will work when i've integrated git-bin into SparkleShare for the next major version.

@hbons hbons closed this Dec 21, 2012

PJaros commented May 1, 2013

I installed Version 1.0.0-1~ppa2 (from the Ubuntu Repository ppa:rebuntu16/sparkleshare+unofficial) on my Ubutntu 12.04 machines over a SparkleShare 0.8 Installation but the creation and the modification time are still not preserved. I really would like to have this patched Version and thought by now it would be in the 1.0 Release. Is the patch working using a Linux <-> Linux Setup? Is it integrated in the 1.0 Release? How do I get a patched Version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment