mostafah / fsync

Keeps files or directories in sync.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Preserve file dates

oscar-b opened this issue · comments

Would it be possible to add the possibility to transfer the file dates (created/modified) from the source files when syncing?

It looks quite straight forward, basically a os.Stat() and a os.Chtimes() (very similar to what you're doing in syncperms() for permissions).

Yes, that should be easy to do, but what needs a little more thinking is providing an interface for controlling that. I’m not sure keeping file dates is something people always want, so there should be a way of setting that as an option.

There is currently one option: deleting extra files in destination or not, and that’s offered as alternate functions, but providing two options as four alternative functions is a little bit crazy. Adding these as extra arguments is not that clean either. So, I’m thinking about something like this:

    type Sync struct {
        Delete    bool
        KeepDates bool
    }

    func (s *Sync) Sync(dst, src string) error

    func (s *Sync) SyncTo(to string, srcs ...string) error

What do you think of that?

I might need some free time for this change, which I hope I’ll find soon enough.

From the documentation:

package fsync keeps two files or directories in sync

"sync" kind of implies to me that as many attributes as possible should be carried over. But if you want to make it optional, that's fine by me :)

@oscar-b I agree that this sounds like the logical default, but since the more widely used rsync has an option for this (-t) - it might be wise to pass that tradition on.

I think this new API is a really good approach to this. It provides a lot of flexibility and allows for future options to be easily added (if the opportunity arises) without disrupting existing codebases.