2015-02-03 20:18:19 +00:00
|
|
|
package restic
|
|
|
|
|
|
|
|
import (
|
2015-05-14 21:06:11 +00:00
|
|
|
"path/filepath"
|
2015-02-03 20:18:19 +00:00
|
|
|
"syscall"
|
2016-08-30 19:44:10 +00:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2015-05-16 11:25:10 +00:00
|
|
|
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
|
|
|
"github.com/restic/restic/internal/fs"
|
2015-02-03 20:18:19 +00:00
|
|
|
)
|
|
|
|
|
2015-05-14 21:06:11 +00:00
|
|
|
func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
|
Fix 567 (#570)
* Patch for https://github.com/restic/restic/issues/567
Backup also files on windows with longer pathnames than 255 chars (e.g. from node).
as fd0 says "So, as far as I can see, we need to have custom methods for all functions that accept a path, so that on Windows we can substitute the normal (possibly relative) path used within restic by an (absolute) UNC path, and only then call the underlying functions like os.Stat(), os.Lstat(), os.Open() and so on.
I've already thought about adding a generic abstraction for the file system (so we can mock this easier in tests), and this looks like a good opportunity to build it."
* fixed building tests
* Restructured patches
Add Wrapper for filepath.Walk
* using \\?\ requires absolute pathes to be used.
Now all tests run
* used gofmt on the code
* Restructured Code. No patches dir, integrate the file functions into restic/fs/
There is still an issue, because restic.fs.Open has a different api the os.Open, which returns the result of OpenFile, but takes only a string
* Changed the last os.Open() calls to fs.Open() after extending the File interface
* fixed name-clash of restic.fs and fuse.fs detected by travis
* fixed fmt with gofmt
* c&p failure: removed fixpath() call.
* missing include
* fixed includes in linux variant
* Fix for Linux. Fd() is required on File interface
* done gofmt
2016-08-15 19:59:13 +00:00
|
|
|
dir, err := fs.Open(filepath.Dir(path))
|
2015-05-14 21:06:11 +00:00
|
|
|
if err != nil {
|
2022-10-16 09:32:38 +00:00
|
|
|
return errors.WithStack(err)
|
2015-05-14 21:06:11 +00:00
|
|
|
}
|
|
|
|
|
2016-08-30 19:44:10 +00:00
|
|
|
times := []unix.Timespec{
|
|
|
|
{Sec: utimes[0].Sec, Nsec: utimes[0].Nsec},
|
|
|
|
{Sec: utimes[1].Sec, Nsec: utimes[1].Nsec},
|
2015-05-16 11:25:10 +00:00
|
|
|
}
|
|
|
|
|
2016-08-30 19:44:10 +00:00
|
|
|
err = unix.UtimesNanoAt(int(dir.Fd()), filepath.Base(path), times, unix.AT_SYMLINK_NOFOLLOW)
|
2015-05-14 21:06:11 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2021-01-30 18:35:46 +00:00
|
|
|
// ignore subsequent errors
|
|
|
|
_ = dir.Close()
|
2016-08-30 19:44:10 +00:00
|
|
|
return errors.Wrap(err, "UtimesNanoAt")
|
2015-05-14 21:06:11 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 18:35:46 +00:00
|
|
|
return dir.Close()
|
2015-05-14 21:06:11 +00:00
|
|
|
}
|
2015-08-14 13:57:47 +00:00
|
|
|
|
2020-10-18 21:39:42 +00:00
|
|
|
func (s statT) atim() syscall.Timespec { return s.Atim }
|
|
|
|
func (s statT) mtim() syscall.Timespec { return s.Mtim }
|
|
|
|
func (s statT) ctim() syscall.Timespec { return s.Ctim }
|