djherbis / times

#golang file times (atime, mtime, ctime, btime)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

times.Stat silently falls back to regular stat on Windows

tmm1 opened this issue · comments

If the platform specific stat fails, the error is silently swallowed and a regular (i.e noctime) stat result is returned:

times/ctime_windows.go

Lines 12 to 17 in fd6b033

ts, err := platformSpecficStat(name)
if err == nil {
return ts, err
}
return stat(name, os.Stat)

This can cause unexpected panics if the caller assumes the return value will be the platform-specific result:

panic: ctime not available

goroutine 108 [running]:
github.com/djherbis/times.noctime.ChangeTime(0xc000be0730, 0x0, 0x0)
	github.com/djherbis/times@v1.2.0/times.go:68 +0x45
github.com/tmm1/myApp/app.createdAtFor(0xc002758075, 0x10, 0xc00138bd51, 0xf3, 0x30)

This is documented, you need to use the Timespec.HasChangeTime to check if it exists.

Thanks I just noticed that as well. I'm curious what the error is, so I may try modifying the package to expose the platform stat or the error somehow.

Yeah I believe the fallback is because if it fails I'm confident it's a permanent error for that file at least (no way to get the time).

But it's been years since I added it. If you find out do you mind posting the results in this issue?

I'm guessing it's the findProc error:
https://github.com/djherbis/times/blob/master/ctime_windows.go#L84

Basically happens when it couldn't load the DLL

I'm seeing this behavior on one particular Windows 10 Pro instance.. the drive with the files is a regular NTFS local drive too.

"platform": "Microsoft Windows 10 Pro",
"platformFamily": "Standalone Workstation",
"platformVersion": "10.0.19042 Build 19042",
"device": "G:",
"mountpoint": "G:",
"fstype": "NTFS",
"opts": "rw.compress"

So I am not convinced this is just an "too old windows" issue.

How would you feel about adding something like times.LastPlatformSpecificStatError() so there's a way to inspect what's going on?

If you're able to test this directly, just modify:
https://github.com/djherbis/times/blob/master/ctime_windows.go#L12

To return platformSpecificStat instead of falling back to regular stat and test it.

If the error is interesting I might consider exporting platformSpecificStat.
If the error is