mirror of https://github.com/restic/restic.git
Move isNewer() into node.go
This commit is contained in:
parent
4bb724fac2
commit
91a2a5f90a
29
node.go
29
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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue