forked from TrueCloudLab/restic
Skip UID/GID and SIGHUP lock-check on Windows
On Windows, User ID/Group ID is not a number, so we ignore any parsing error that may come from attempting to convert it to an integer. It will simply be '0'. Don't defer the process Release until we have checked the error. Skip the SIGHUP connection attempt on Windows. If the process exists, we assume it is running.
This commit is contained in:
parent
5d5f3de62f
commit
3504ea3992
1 changed files with 14 additions and 14 deletions
18
lock.go
18
lock.go
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/repository"
|
"github.com/restic/restic/repository"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Lock represents a process locking the repository for an operation.
|
// Lock represents a process locking the repository for an operation.
|
||||||
|
@ -116,16 +117,12 @@ func (l *Lock) fillUserInfo() error {
|
||||||
}
|
}
|
||||||
l.Username = usr.Username
|
l.Username = usr.Username
|
||||||
|
|
||||||
uid, err := strconv.ParseInt(usr.Uid, 10, 32)
|
// We ignore the error. On Windows Uid is not a number
|
||||||
if err != nil {
|
uid, _ := strconv.ParseInt(usr.Uid, 10, 32)
|
||||||
return err
|
|
||||||
}
|
|
||||||
l.UID = uint32(uid)
|
l.UID = uint32(uid)
|
||||||
|
|
||||||
gid, err := strconv.ParseInt(usr.Gid, 10, 32)
|
// We ignore the error. On Windows Gid is not a number
|
||||||
if err != nil {
|
gid, _ := strconv.ParseInt(usr.Gid, 10, 32)
|
||||||
return err
|
|
||||||
}
|
|
||||||
l.GID = uint32(gid)
|
l.GID = uint32(gid)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -207,18 +204,21 @@ func (l *Lock) Stale() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
proc, err := os.FindProcess(l.PID)
|
proc, err := os.FindProcess(l.PID)
|
||||||
defer proc.Release()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("Lock.Stale", "error searching for process %d: %v\n", l.PID, err)
|
debug.Log("Lock.Stale", "error searching for process %d: %v\n", l.PID, err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
defer proc.Release()
|
||||||
|
|
||||||
|
// Windows does not have SIGHUP
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
debug.Log("Lock.Stale", "sending SIGHUP to process %d\n", l.PID)
|
debug.Log("Lock.Stale", "sending SIGHUP to process %d\n", l.PID)
|
||||||
err = proc.Signal(syscall.SIGHUP)
|
err = proc.Signal(syscall.SIGHUP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("Lock.Stale", "signal error: %v, lock is probably stale\n", err)
|
debug.Log("Lock.Stale", "signal error: %v, lock is probably stale\n", err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
debug.Log("Lock.Stale", "lock not stale\n")
|
debug.Log("Lock.Stale", "lock not stale\n")
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in a new issue