-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from fako1024/main
Support PreserveTimes for symlinks on Unix
- Loading branch information
Showing
9 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build !windows && !plan9 && !js | ||
// +build !windows,!plan9,!js | ||
|
||
package copy | ||
|
||
import ( | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func preserveLtimes(src, dest string) error { | ||
info := new(unix.Stat_t) | ||
if err := unix.Lstat(src, info); err != nil { | ||
return err | ||
} | ||
|
||
return unix.Lutimes(dest, []unix.Timeval{ | ||
unix.NsecToTimeval(info.Atim.Nano()), | ||
unix.NsecToTimeval(info.Mtim.Nano()), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build !windows && !plan9 && !js | ||
// +build !windows,!plan9,!js | ||
|
||
package copy | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
. "github.com/otiai10/mint" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func TestOptions_PreserveLTimes(t *testing.T) { | ||
err := Copy("test/data/case15", "test/data.copy/case15") | ||
Expect(t, err).ToBe(nil) | ||
opt := Options{PreserveTimes: true} | ||
err = Copy("test/data/case15", "test/data.copy/case15-preserveltimes", opt) | ||
Expect(t, err).ToBe(nil) | ||
|
||
orig, err := os.Lstat("test/data/case15/symlink") | ||
Expect(t, err).ToBe(nil) | ||
plain, err := os.Lstat("test/data.copy/case15/symlink") | ||
Expect(t, err).ToBe(nil) | ||
preserved, err := os.Lstat("test/data.copy/case15-preserveltimes/symlink") | ||
Expect(t, err).ToBe(nil) | ||
Expect(t, plain.ModTime().Unix()).Not().ToBe(orig.ModTime().Unix()) | ||
Expect(t, preserved.ModTime().Unix()).ToBe(orig.ModTime().Unix()) | ||
} | ||
|
||
func TestOptions_PreserveLTimesErrorReturn(t *testing.T) { | ||
err := preserveLtimes("doesnotexist_original.txt", "doesnotexist_copy.txt") | ||
Expect(t, err).ToBe(unix.ENOENT) | ||
Expect(t, os.IsNotExist(err)).ToBe(true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build windows || js || plan9 | ||
// +build windows js plan9 | ||
|
||
package copy | ||
|
||
func preserveLtimes(src, dest string) error { | ||
return nil // Unsupported | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build windows || js || plan9 | ||
// +build windows js plan9 | ||
|
||
package copy | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
. "github.com/otiai10/mint" | ||
) | ||
|
||
func TestOptions_PreserveLTimes(t *testing.T) { | ||
err := Copy("test/data/case15", "test/data.copy/case15") | ||
Expect(t, err).ToBe(nil) | ||
opt := Options{PreserveTimes: true} | ||
err = Copy("test/data/case15", "test/data.copy/case15-preserveltimes", opt) | ||
Expect(t, err).ToBe(nil) | ||
|
||
orig, err := os.Lstat("test/data/case15/symlink") | ||
Expect(t, err).ToBe(nil) | ||
plain, err := os.Lstat("test/data.copy/case15/symlink") | ||
Expect(t, err).ToBe(nil) | ||
preserved, err := os.Lstat("test/data.copy/case15-preserveltimes/symlink") | ||
Expect(t, err).ToBe(nil) | ||
Expect(t, plain.ModTime().Unix()).Not().ToBe(orig.ModTime().Unix()) | ||
Expect(t, preserved.ModTime().Unix()).Not().ToBe(orig.ModTime().Unix()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
File with specific atime and mtime. | ||
|
||
These two properties should be preserved if we provide the PreserveTimes options to copy.Copy. | ||
|
||
The properties should be preserverd also for the directories and the links. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
README.md |