diff --git a/internal/unpackinfo/lchtimes.go b/internal/unpackinfo/lchtimes_darwin.go similarity index 95% rename from internal/unpackinfo/lchtimes.go rename to internal/unpackinfo/lchtimes_darwin.go index ad1c959..201a83e 100644 --- a/internal/unpackinfo/lchtimes.go +++ b/internal/unpackinfo/lchtimes_darwin.go @@ -1,5 +1,5 @@ -//go:build darwin || linux -// +build darwin linux +//go:build darwin +// +build darwin package unpackinfo diff --git a/internal/unpackinfo/lchtimes_linux.go b/internal/unpackinfo/lchtimes_linux.go new file mode 100644 index 0000000..1a929e8 --- /dev/null +++ b/internal/unpackinfo/lchtimes_linux.go @@ -0,0 +1,30 @@ +//go:build linux +// +build linux + +package unpackinfo + +import ( + "golang.org/x/sys/unix" +) + +// Lchtimes modifies the access and modified timestamps on a target path +// 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: i.OriginalAccessTime.UnixMicro() % 1000}, + {Sec: i.OriginalModTime.Unix(), Usec: 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 +}