Skip to content

Fix handing modification time of lock file #12

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions storage/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storage
import (
"os"
"path/filepath"
"reflect"
"sync"
"time"

Expand Down Expand Up @@ -134,6 +135,22 @@ func (l *lockfile) TouchedSince(when time.Time) bool {
if err != nil {
return true
}
touched := time.Unix(st.Mtimespec.Unix())
return when.Before(touched)
t := reflect.TypeOf(st)
// OSX
if _, found := t.FieldByName("Mtimespec"); found {
mtime, ok := reflect.ValueOf(st).FieldByName("Mtimespec").Interface().(unix.Timespec)
if !ok {
panic("unable to read modification time")
}
return when.Before(time.Unix(mtime.Unix()))
}
// Linux
if _, found := t.FieldByName("Mtim"); found {
mtime, ok := reflect.ValueOf(st).FieldByName("Mtim").Interface().(unix.Timespec)
if !ok {
panic("unable to read modification time")
}
return when.Before(time.Unix(mtime.Unix()))
}
panic("unable to read modification time")
}