diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index efdb776..278a0af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,29 @@ name: test on: [push] jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + goos: [linux, windows, darwin] + goarch: ["386", amd64, arm64] + exclude: + - goarch: "386" + goos: darwin + - goarch: arm64 + goos: windows + steps: + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + + - name: setup go + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 + with: + go-version-file: go.mod + + - name: build + run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build + unit-test: runs-on: ubuntu-latest steps: diff --git a/internal/unpackinfo/lchtimes_linux32.go b/internal/unpackinfo/lchtimes_linux32.go new file mode 100644 index 0000000..f456791 --- /dev/null +++ b/internal/unpackinfo/lchtimes_linux32.go @@ -0,0 +1,28 @@ +//go:build linux_amd || linux_arm +// +build linux_amd linux_arm + +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. +func (i UnpackInfo) Lchtimes() error { + return unix.Lutimes(i.Path, []unix.Timeval{ + {Sec: i.OriginalAccessTime.Unix(), Usec: int32(i.OriginalAccessTime.Nanosecond() / 1e6 % 1e6)}, + {Sec: i.OriginalModTime.Unix(), Usec: int32(i.OriginalModTime.Nanosecond() / 1e6 % 1e6)}}, + ) +} + +// 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_linux.go b/internal/unpackinfo/lchtimes_linux64.go similarity index 93% rename from internal/unpackinfo/lchtimes_linux.go rename to internal/unpackinfo/lchtimes_linux64.go index c9ed6b3..e3dadc3 100644 --- a/internal/unpackinfo/lchtimes_linux.go +++ b/internal/unpackinfo/lchtimes_linux64.go @@ -1,5 +1,5 @@ -//go:build linux -// +build linux +//go:build linux_amd64 || linux_arm64 +// +build linux_amd64 linux_arm64 package unpackinfo diff --git a/internal/unpackinfo/lchtimes_others.go b/internal/unpackinfo/lchtimes_others.go index 1219ba4..7a6c649 100644 --- a/internal/unpackinfo/lchtimes_others.go +++ b/internal/unpackinfo/lchtimes_others.go @@ -1,5 +1,5 @@ -//go:build !(linux || darwin) -// +build !linux,!darwin +//go:build !darwin && !linux_amd64 && !linux_arm64 && !linux_amd && !linux_arm +// +build !darwin,!linux_amd64,!linux_arm64,!linux_amd,!linux_arm package unpackinfo