diff --git a/internal/unpackinfo/lchtimes.go b/internal/unpackinfo/lchtimes.go index fa01b4e..ad1c959 100644 --- a/internal/unpackinfo/lchtimes.go +++ b/internal/unpackinfo/lchtimes.go @@ -8,10 +8,23 @@ import ( ) // Lchtimes modifies the access and modified timestamps on a target path -// This capability is only available on Linux and Darwin as of now. +// This capability is only available on Linux and Darwin as of now. The +// timestamps within UnpackInfo would have already been rounded by +// archive/tar so there is no need for subsecond precision. func (i UnpackInfo) Lchtimes() error { return unix.Lutimes(i.Path, []unix.Timeval{ {Sec: i.OriginalAccessTime.Unix(), Usec: int32(i.OriginalAccessTime.UnixMicro() % 1000)}, {Sec: i.OriginalModTime.Unix(), Usec: int32(i.OriginalModTime.UnixMicro() % 1000)}}, ) } + +// CanMaintainSymlinkTimestamps determines whether is is possible to change +// timestamps on symlinks for the the current platform. For regular files +// and directories, attempts are made to restore permissions and timestamps +// after extraction. But for symbolic links, go's cross-platform +// packages (Chmod and Chtimes) are not capable of changing symlink info +// because those methods follow the symlinks. However, a platform-dependent option +// is provided for linux and darwin (see Lchtimes) +func CanMaintainSymlinkTimestamps() bool { + return true +} diff --git a/internal/unpackinfo/lchtimes_others.go b/internal/unpackinfo/lchtimes_others.go index 0b5c3cb..1219ba4 100644 --- a/internal/unpackinfo/lchtimes_others.go +++ b/internal/unpackinfo/lchtimes_others.go @@ -12,3 +12,14 @@ import ( func (i UnpackInfo) Lchtimes() error { return errors.New("Lchtimes is not supported on this platform") } + +// CanMaintainSymlinkTimestamps determines whether is is possible to change +// timestamps on symlinks for the the current platform. For regular files +// and directories, attempts are made to restore permissions and timestamps +// after extraction. But for symbolic links, go's cross-platform +// packages (Chmod and Chtimes) are not capable of changing symlink info +// because those methods follow the symlinks. However, a platform-dependent option +// is provided for linux and darwin (see Lchtimes) +func CanMaintainSymlinkTimestamps() bool { + return false +} diff --git a/internal/unpackinfo/unpackinfo.go b/internal/unpackinfo/unpackinfo.go index f1ba700..6b21406 100644 --- a/internal/unpackinfo/unpackinfo.go +++ b/internal/unpackinfo/unpackinfo.go @@ -7,7 +7,6 @@ import ( "io/fs" "os" "path/filepath" - "runtime" "strings" "time" ) @@ -109,17 +108,6 @@ func (i UnpackInfo) IsRegular() bool { return i.Typeflag == tar.TypeReg || i.Typeflag == tar.TypeRegA } -// CanMaintainSymlinkTimestamps determines whether is is possible to change -// timestamps on symlinks for the the current platform. For regular files -// and directories, attempts are made to restore permissions and timestamps -// after extraction. But for symbolic links, go's cross-platform -// packages (Chmod and Chtimes) are not capable of changing symlink info -// because those methods follow the symlinks. However, a platform-dependent option -// is provided for linux and darwin (see Lchtimes) -func CanMaintainSymlinkTimestamps() bool { - return runtime.GOOS == "linux" || runtime.GOOS == "darwin" -} - // RestoreInfo changes the file mode and timestamps for the given UnpackInfo data func (i UnpackInfo) RestoreInfo() error { switch {