2
2
mirror of https://github.com/octoleo/restic.git synced 2024-09-29 06:59:01 +00:00
restic/node_darwin.go

72 lines
1.4 KiB
Go
Raw Normal View History

package restic
2015-02-03 20:32:01 +00:00
import (
"fmt"
"os"
"os/user"
"strconv"
"syscall"
"time"
2015-03-08 13:32:49 +00:00
"github.com/restic/restic/debug"
2015-02-03 20:32:01 +00:00
)
2015-04-25 00:36:54 +00:00
func (node *Node) OpenForReading() (*os.File, error) {
2015-04-25 17:02:19 +00:00
return os.Open(node.path)
2015-04-25 00:36:54 +00:00
}
2015-04-29 01:24:43 +00:00
func (node *Node) fillExtra(path string, fi os.FileInfo) error {
2015-02-03 20:32:01 +00:00
stat, ok := fi.Sys().(*syscall.Stat_t)
if !ok {
2015-04-29 01:24:43 +00:00
return nil
2015-02-03 20:32:01 +00:00
}
node.ChangeTime = time.Unix(stat.Ctimespec.Unix())
node.AccessTime = time.Unix(stat.Atimespec.Unix())
node.UID = stat.Uid
node.GID = stat.Gid
2015-04-29 01:24:43 +00:00
if u, err := user.LookupId(strconv.Itoa(int(stat.Uid))); err == nil {
2015-02-03 20:32:01 +00:00
node.User = u.Username
}
node.Inode = stat.Ino
2015-04-29 01:24:43 +00:00
var err error
2015-02-03 20:32:01 +00:00
switch node.Type {
case "file":
node.Size = uint64(stat.Size)
node.Links = uint64(stat.Nlink)
case "dir":
case "symlink":
node.LinkTarget, err = os.Readlink(path)
case "dev":
node.Device = uint64(stat.Rdev)
case "chardev":
node.Device = uint64(stat.Rdev)
case "fifo":
case "socket":
default:
2015-04-29 01:24:43 +00:00
err = fmt.Errorf("invalid node type %q", node.Type)
2015-02-03 20:32:01 +00:00
}
return err
}
func (node *Node) createDevAt(path string) error {
2015-02-03 20:32:01 +00:00
return syscall.Mknod(path, syscall.S_IFBLK|0600, int(node.Device))
}
func (node *Node) createCharDevAt(path string) error {
2015-02-03 20:32:01 +00:00
return syscall.Mknod(path, syscall.S_IFCHR|0600, int(node.Device))
}
func (node *Node) createFifoAt(path string) error {
2015-02-03 20:32:01 +00:00
return syscall.Mkfifo(path, 0600)
}
2015-03-08 13:32:49 +00:00
2015-04-29 03:31:07 +00:00
func changeTime(stat *syscall.Stat_t) time.Unix {
return time.Unix(stat.Ctimespec.Unix())
2015-03-08 13:32:49 +00:00
}