github.com/sshnaidm/storage@v1.12.13/lockfile_windows.go (about) 1 // +build windows 2 3 package storage 4 5 import ( 6 "os" 7 "sync" 8 "time" 9 ) 10 11 // createLockerForPath returns a Locker object, possibly (depending on the platform) 12 // working inter-process and associated with the specified path. 13 // 14 // This function will be called at most once for each path value within a single process. 15 // 16 // If ro, the lock is a read-write lock and the returned Locker should correspond to the 17 // “lock for reading” (shared) operation; otherwise, the lock is either an exclusive lock, 18 // or a read-write lock and Locker should correspond to the “lock for writing” (exclusive) operation. 19 // 20 // WARNING: 21 // - The lock may or MAY NOT be inter-process. 22 // - There may or MAY NOT be an actual object on the filesystem created for the specified path. 23 // - Even if ro, the lock MAY be exclusive. 24 func createLockerForPath(path string, ro bool) (Locker, error) { 25 return &lockfile{locked: false}, nil 26 } 27 28 type lockfile struct { 29 mu sync.Mutex 30 file string 31 locked bool 32 } 33 34 func (l *lockfile) Lock() { 35 l.mu.Lock() 36 l.locked = true 37 } 38 39 func (l *lockfile) RecursiveLock() { 40 // We don't support Windows but a recursive writer-lock in one process-space 41 // is really a writer lock, so just panic. 42 panic("not supported") 43 } 44 45 func (l *lockfile) RLock() { 46 l.mu.Lock() 47 l.locked = true 48 } 49 50 func (l *lockfile) Unlock() { 51 l.locked = false 52 l.mu.Unlock() 53 } 54 55 func (l *lockfile) Locked() bool { 56 return l.locked 57 } 58 59 func (l *lockfile) Modified() (bool, error) { 60 return false, nil 61 } 62 func (l *lockfile) Touch() error { 63 return nil 64 } 65 func (l *lockfile) IsReadWrite() bool { 66 return false 67 } 68 69 func (l *lockfile) TouchedSince(when time.Time) bool { 70 stat, err := os.Stat(l.file) 71 if err != nil { 72 return true 73 } 74 return when.Before(stat.ModTime()) 75 }