From 262e5a8b4a3f0b9e741baa5c597955cb2fd145a1 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Sat, 25 Apr 2015 00:36:54 +0000 Subject: [PATCH] O_NOATIME on Linux --- archiver.go | 2 +- node_darwin.go | 4 ++++ node_linux.go | 4 ++++ node_windows.go | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/archiver.go b/archiver.go index 6b58a609d..fab11226f 100644 --- a/archiver.go +++ b/archiver.go @@ -169,7 +169,7 @@ func (arch *Archiver) SaveTreeJSON(item interface{}) (Blob, error) { // SaveFile stores the content of the file on the backend as a Blob by calling // Save for each chunk. func (arch *Archiver) SaveFile(p *Progress, node *Node) (Blobs, error) { - file, err := os.Open(node.path) + file, err := node.OpenForReading() defer file.Close() if err != nil { return nil, err diff --git a/node_darwin.go b/node_darwin.go index ff1c2d2c1..035fdf1c2 100644 --- a/node_darwin.go +++ b/node_darwin.go @@ -11,6 +11,10 @@ import ( "github.com/restic/restic/debug" ) +func (node *Node) OpenForReading() (*os.File, error) { + return os.Open(n.path) +} + func (node *Node) fill_extra(path string, fi os.FileInfo) (err error) { stat, ok := fi.Sys().(*syscall.Stat_t) if !ok { diff --git a/node_linux.go b/node_linux.go index 1c7552188..ec7175491 100644 --- a/node_linux.go +++ b/node_linux.go @@ -11,6 +11,10 @@ import ( "github.com/restic/restic/debug" ) +func (node *Node) OpenForReading() (*os.File, error) { + return os.OpenFile(node.path, os.O_RDONLY|syscall.O_NOATIME, 0) +} + func (node *Node) fill_extra(path string, fi os.FileInfo) error { stat, ok := fi.Sys().(*syscall.Stat_t) if !ok { diff --git a/node_windows.go b/node_windows.go index 884c33d1c..15a475330 100644 --- a/node_windows.go +++ b/node_windows.go @@ -2,6 +2,10 @@ package restic import "os" +func (node *Node) OpenForReading() (*os.File, error) { + return os.Open(n.path) +} + func (node *Node) fill_extra(path string, fi os.FileInfo) error { return nil }