2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 11:28:54 +00:00

Move isNewer() into node.go

This commit is contained in:
Florian Weingarten 2015-04-29 03:31:07 +00:00
parent 4bb724fac2
commit 91a2a5f90a
3 changed files with 33 additions and 56 deletions

29
node.go
View File

@ -10,6 +10,7 @@ import (
"github.com/juju/arrar"
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
"github.com/restic/restic/server"
)
@ -308,3 +309,31 @@ func (node Node) sameContent(other Node) bool {
return true
}
func (node *Node) isNewer(path string, fi os.FileInfo) bool {
if node.Type != "file" {
debug.Log("node.isNewer", "node %v is newer: not file", path)
return true
}
tpe := nodeTypeFromFileInfo(fi)
if node.Name != fi.Name() || node.Type != tpe {
debug.Log("node.isNewer", "node %v is newer: name or type changed", path)
return true
}
extendedStat := fi.Sys().(*syscall.Stat_t)
inode := extendedStat.Ino
size := uint64(extendedStat.Size)
if node.ModTime != fi.ModTime() ||
node.ChangeTime != changeTime(extendedStat) ||
node.Inode != inode ||
node.Size != size {
debug.Log("node.isNewer", "node %v is newer: timestamp, size or inode changed", path)
return true
}
debug.Log("node.isNewer", "node %v is not newer", path)
return false
}

View File

@ -66,31 +66,6 @@ func (node *Node) createFifoAt(path string) error {
return syscall.Mkfifo(path, 0600)
}
func (node *Node) isNewer(path string, fi os.FileInfo) bool {
if node.Type != "file" {
debug.Log("node.isNewer", "node %v is newer: not file", path)
return true
}
tpe := nodeTypeFromFileInfo(fi)
if node.Name != fi.Name() || node.Type != tpe {
debug.Log("node.isNewer", "node %v is newer: name or type changed", path)
return false
}
extendedStat := fi.Sys().(*syscall.Stat_t)
changeTime := time.Unix(extendedStat.Ctimespec.Unix())
inode := extendedStat.Ino
size := uint64(extendedStat.Size)
if node.ModTime != fi.ModTime() ||
node.ChangeTime != changeTime ||
node.Inode != inode ||
node.Size != size {
debug.Log("node.isNewer", "node %v is newer: timestamp or inode changed", path)
return false
}
debug.Log("node.isNewer", "node %v is not newer", path)
return false
func changeTime(stat *syscall.Stat_t) time.Unix {
return time.Unix(stat.Ctimespec.Unix())
}

View File

@ -7,8 +7,6 @@ import (
"strconv"
"syscall"
"time"
"github.com/restic/restic/debug"
)
func (node *Node) OpenForReading() (*os.File, error) {
@ -70,31 +68,6 @@ func (node *Node) createFifoAt(path string) error {
return syscall.Mkfifo(path, 0600)
}
func (node *Node) isNewer(path string, fi os.FileInfo) bool {
if node.Type != "file" {
debug.Log("node.isNewer", "node %v is newer: not file", path)
return true
}
tpe := nodeTypeFromFileInfo(fi)
if node.Name != fi.Name() || node.Type != tpe {
debug.Log("node.isNewer", "node %v is newer: name or type changed", path)
return true
}
extendedStat := fi.Sys().(*syscall.Stat_t)
changeTime := time.Unix(extendedStat.Ctim.Unix())
inode := extendedStat.Ino
size := uint64(extendedStat.Size)
if node.ModTime != fi.ModTime() ||
node.ChangeTime != changeTime ||
node.Inode != inode ||
node.Size != size {
debug.Log("node.isNewer", "node %v is newer: timestamp, size or inode changed", path)
return true
}
debug.Log("node.isNewer", "node %v is not newer", path)
return false
func changeTime(stat *syscall.Stat_t) time.Time {
return time.Unix(stat.Ctim.Unix())
}