From 91a2a5f90a941aa3b2c00d64d5e79f7a6eca718d Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Wed, 29 Apr 2015 03:31:07 +0000 Subject: [PATCH] Move isNewer() into node.go --- node.go | 29 +++++++++++++++++++++++++++++ node_darwin.go | 29 ++--------------------------- node_linux.go | 31 ++----------------------------- 3 files changed, 33 insertions(+), 56 deletions(-) diff --git a/node.go b/node.go index fe62bd273..aab2aa8a8 100644 --- a/node.go +++ b/node.go @@ -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 +} diff --git a/node_darwin.go b/node_darwin.go index ae4b0060a..666a576ff 100644 --- a/node_darwin.go +++ b/node_darwin.go @@ -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()) } diff --git a/node_linux.go b/node_linux.go index 812621d5c..7ba11e943 100644 --- a/node_linux.go +++ b/node_linux.go @@ -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()) }