mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-22 16:25:38 +00:00
Merge pull request #80 from vbatts/bsd_compat
keywords: BSD compat for a few keywords
This commit is contained in:
commit
c5fc89d0f1
3 changed files with 45 additions and 1 deletions
|
@ -3,8 +3,12 @@
|
||||||
package mtree
|
package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -12,4 +16,42 @@ var (
|
||||||
// ideally this will pull in from here https://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=2
|
// ideally this will pull in from here https://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=2
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) {
|
||||||
|
if hdr, ok := info.Sys().(*tar.Header); ok {
|
||||||
|
return fmt.Sprintf("uname=%s", hdr.Uname), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
stat := info.Sys().(*syscall.Stat_t)
|
||||||
|
u, err := user.LookupId(fmt.Sprintf("%d", stat.Uid))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("uname=%s", u.Username), nil
|
||||||
|
}
|
||||||
|
uidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) {
|
||||||
|
if hdr, ok := info.Sys().(*tar.Header); ok {
|
||||||
|
return fmt.Sprintf("uid=%d", hdr.Uid), nil
|
||||||
|
}
|
||||||
|
stat := info.Sys().(*syscall.Stat_t)
|
||||||
|
return fmt.Sprintf("uid=%d", stat.Uid), nil
|
||||||
|
}
|
||||||
|
gidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) {
|
||||||
|
if hdr, ok := info.Sys().(*tar.Header); ok {
|
||||||
|
return fmt.Sprintf("gid=%d", hdr.Gid), nil
|
||||||
|
}
|
||||||
|
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||||
|
return fmt.Sprintf("gid=%d", stat.Gid), nil
|
||||||
|
}
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
nlinkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) {
|
||||||
|
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||||
|
return fmt.Sprintf("nlink=%d", stat.Nlink), nil
|
||||||
|
}
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
xattrKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build linux
|
||||||
|
|
||||||
package mtree
|
package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build !linux
|
// +build !linux,!darwin,!freebsd,!netbsd,!openbsd
|
||||||
|
|
||||||
package mtree
|
package mtree
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue