otiai10 / copy

Go copy directory recursively

Home Page:https://pkg.go.dev/github.com/otiai10/copy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

opt.Untouchable + opt.PreserveTimes error copying subdirectory

enthor opened this issue · comments

This is very minor issue. But interesting.

Here is error log from my code, which I provide for clarity:

Final: main.go#DoitRunApps(): error App.RunApp(), error = AppLogicCustomStartAsOfDt.RunApp(): (15) Normal Daily Run utility.go#Otiai10CopyMerge() error, in=data, out=bkp/d20210305, error = chtimes bkp/d20210305/downloads: no such file or directory

I decided to use OnDirExists.Untouchable for first test of certain logic in my code, as opposed to
Merge. Also using opt.PreserveTimes = true. Copying directory data=/ which contains data/downloads, data/in and data/out. Destination is bkp/d20210305 where subdirectory
d20210305 must be created as part of the copy -- which it was. The error occurred in
subdirectory downloads/ which was not created.

So...it appears to me that switchboard() code is not liking the fact that destination
bkp/d20210305/downloads failed to exist:

if opt.PreserveTimes { spec := getTimeSpec(info) if err := os.Chtimes(dest, spec.Atime, spec.Mtime); err != nil { return err } }

Thus, the apparent logical difficulty: if directory does not exist then why preserve times?

I will workaround by simply not using PreserveTimes=true in this instance. I suppose
just adding a documentation note about the incompatiblity of these options would
suffice. Or, perhaps, add a line of code or two.

Thus, the apparent logical difficulty: if directory does not exist then why preserve times?

Thanks, good catch!
Let me tackle it.