mirror of
https://github.com/octoleo/restic.git
synced 2024-11-29 16:23:59 +00:00
Create uid/gid convertion function.
Create separate function to convert user ID / group ID of a user to integer. Windows is a stub, since this doesn't work on Windows (uid/gid is not a number).
This commit is contained in:
parent
0e7d0d8dba
commit
e1f6bbac9f
12
lock.go
12
lock.go
@ -5,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"os/user"
|
"os/user"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -117,15 +116,8 @@ func (l *Lock) fillUserInfo() error {
|
|||||||
}
|
}
|
||||||
l.Username = usr.Username
|
l.Username = usr.Username
|
||||||
|
|
||||||
// We ignore the error. On Windows Uid is not a number
|
l.UID, l.GID, err = uidGidInt(*usr)
|
||||||
uid, _ := strconv.ParseInt(usr.Uid, 10, 32)
|
return err
|
||||||
l.UID = uint32(uid)
|
|
||||||
|
|
||||||
// We ignore the error. On Windows Gid is not a number
|
|
||||||
gid, _ := strconv.ParseInt(usr.Gid, 10, 32)
|
|
||||||
l.GID = uint32(gid)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkForOtherLocks looks for other locks that currently exist in the repository.
|
// checkForOtherLocks looks for other locks that currently exist in the repository.
|
||||||
|
24
lock_unix.go
Normal file
24
lock_unix.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package restic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/user"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// uidGidInt returns uid, gid of the user as a number.
|
||||||
|
func uidGidInt(u user.User) (uid, gid uint32, err error) {
|
||||||
|
var ui, gi int
|
||||||
|
ui, err = strconv.ParseInt(u.Uid, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gi, err = strconv.ParseInt(u.Gid, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uid = uint32(ui)
|
||||||
|
gid = uint32(gi)
|
||||||
|
return
|
||||||
|
}
|
10
lock_windows.go
Normal file
10
lock_windows.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package restic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// uidGidInt always returns 0 on Windows, since uid isn't numbers
|
||||||
|
func uidGidInt(u user.User) (uid, gid uint32, err error) {
|
||||||
|
return 0, 0, nil
|
||||||
|
}
|
13
snapshot.go
13
snapshot.go
@ -5,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
@ -76,15 +75,9 @@ func (sn *Snapshot) fillUserInfo() error {
|
|||||||
}
|
}
|
||||||
sn.Username = usr.Username
|
sn.Username = usr.Username
|
||||||
|
|
||||||
// We ignore the error. On Windows Uid is not a number
|
// set userid and groupid
|
||||||
uid, _ := strconv.ParseInt(usr.Uid, 10, 32)
|
sn.UID, sn.GID, err = uidGidInt(*usr)
|
||||||
sn.UID = uint32(uid)
|
return err
|
||||||
|
|
||||||
// We ignore the error. On Windows Gid is not a number
|
|
||||||
gid, _ := strconv.ParseInt(usr.Gid, 10, 32)
|
|
||||||
sn.GID = uint32(gid)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindSnapshot takes a string and tries to find a snapshot whose ID matches
|
// FindSnapshot takes a string and tries to find a snapshot whose ID matches
|
||||||
|
Loading…
Reference in New Issue
Block a user