Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare timestamps during "sync" function #8

Open
tkhyn opened this issue Feb 27, 2017 · 3 comments
Open

Compare timestamps during "sync" function #8

tkhyn opened this issue Feb 27, 2017 · 3 comments
Labels
bug Something isn't working major

Comments

@tkhyn
Copy link
Owner

tkhyn commented Feb 27, 2017

Original report by Igor Krbavcic (Bitbucket: bolon_yokte, ).


Hi, I noticed a behaviour that I consider unexpected in 2.3.0.A.0.
I wanted dirsync to sync two folders in a way that the destination gets overwritten (updated, purged, new files added, with the exception of .svn folders that are there) completely with all the content.
If found out that it had to be done with the following line of code:

#!python

sync(src_folder, dst_folder, action='sync', purge=True, verbose=False, ignore=[r'((.*\/)|(^))\.svn.*'])

I went through a bit of trouble until I found out that files are represented without its base folder to find a proper regex expression to filter the right files...

Anyway, I change several files in the destination folder before doing some other functions on them; and next time I want them overwritten with the original files.
That didn't seem to be possible with the original options - as if ctime=True was always on.

I found out that I had to change this line of _cmptimestamps function:

#!python

mtime_cmp = int((filest1.st_mtime - filest2.st_mtime) * 1000) > 0

to this:

#!python

mtime_cmp = int((filest1.st_mtime - filest2.st_mtime) * 1000) != 0

for it to work properly (or at lease as I intended it to).

It would be really helpful if documentation is on the level of the software itself... ;)

Otherwise thank you for the very useful code.
Regards,
Igor

@tkhyn
Copy link
Owner Author

tkhyn commented Feb 27, 2017

Hi Igor,

I think the behavior you're expecting (mirroring a directory to another) could be obtained using action='update' instead of action='sync'. The update action will bypass the timestamp check and will only be 'one-way' (files in the target directory will never be copied to the source).

@tkhyn
Copy link
Owner Author

tkhyn commented Feb 27, 2017

Original comment by Igor Krbavcic (Bitbucket: bolon_yokte, ).


I know what you mean. But does that mean I need to use sync and update functions separately to achieve what I need (update of files, copy new files and purge destination from non existing files in source)?

@tkhyn
Copy link
Owner Author

tkhyn commented Feb 27, 2017

Hi Igor, in the current version of the code, yes you would need to run 'update' first, and then 'sync'. Indeed, 'update' will not copy new files. I think that was the original behavior of the script dirsync comes from and I never changed it. But given the feedback I have on this (with similar issues being reported), I may consider making 'update' actually copy the new files, so that in your case you would only need 'update'. And even rename 'update' by 'mirror' to make it more explicit.

@tkhyn tkhyn added major bug Something isn't working labels Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working major
Projects
None yet
Development

No branches or pull requests

1 participant