diff options
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | archive.go | 17 | ||||
-rw-r--r-- | installpkg.go | 23 | ||||
-rw-r--r-- | removepkg_integration_test.go | 4 |
4 files changed, 48 insertions, 9 deletions
@@ -63,3 +63,16 @@ These tools will likely not be included: - makepkg - pkgdiff - pkgtool + +## Operation Notes + +### Unsupported tar attributes + +These tools will exit with error in the unlikely event the package has +unsupported file attributes, like PAX. You can opt to ignore them via an +environment variable. + +``` + export PKGTOOLS_GO_STRICT=NO + installpkg some-cool-package.txz +``` @@ -124,6 +124,8 @@ type TarCfg struct { Root string Chown bool Chmod bool + // Strict bails out when anything unexpected is encountered. + Strict bool } type TarExtracter struct { @@ -140,6 +142,21 @@ func (s *TarExtracter) FilterTar( ) error { target := path.Join(s.cfg.Root, header.Name) + if s.cfg.Strict { + if len(header.PAXRecords) > 0 { + return errors.Errorf( + "%s: contains unsupported PAXRecords, bailing out", + header.Name, + ) + } + if len(header.Xattrs) > 0 { + return errors.Errorf( + "%s: contains unsupported extended attributes, bailing out", + header.Name, + ) + } + } + var err error switch header.Typeflag { case tar.TypeBlock: diff --git a/installpkg.go b/installpkg.go index 479b318..488692e 100644 --- a/installpkg.go +++ b/installpkg.go @@ -65,11 +65,13 @@ type InstallPkgFlags struct { TerseLength int Warn bool - chown bool - chmod bool + chown bool + chmod bool + Strict bool } var DefaultInstallPkgFlags = InstallPkgFlags{ + // Official slackware configuration Ask: false, InfoBox: false, LockDir: InstallLockDir, @@ -83,8 +85,10 @@ var DefaultInstallPkgFlags = InstallPkgFlags{ TerseLength: DefaultTerseLength, Warn: false, - chown: true, - chmod: true, + // ours + chown: false, + chmod: false, + Strict: true, } func (s *InstallPkgFlags) SetEnvValues() { @@ -97,6 +101,10 @@ func (s *InstallPkgFlags) SetEnvValues() { if v := os.Getenv("ROOT"); v != "" { s.Root = v } + + if v := os.Getenv("PKGTOOLS_GO_STRICT"); v != "NO" { + s.Strict = false + } } func runInstallScript( @@ -301,9 +309,10 @@ func extractSlackwarePkg(flags *InstallPkgFlags, fp string) error { defer slackPkg.Close() toRoot := NewTarExtractor(&TarCfg{ - Root: flags.Root, - Chmod: flags.chmod, - Chown: flags.chown, + Root: flags.Root, + Chmod: flags.chmod, + Chown: flags.chown, + Strict: flags.Strict, }) err = FilterTar( diff --git a/removepkg_integration_test.go b/removepkg_integration_test.go index 15801bd..5048914 100644 --- a/removepkg_integration_test.go +++ b/removepkg_integration_test.go @@ -76,16 +76,16 @@ func TestInstallAll(t *testing.T) { from := os.Getenv("SOURCE") pkgs, err := findSlackwarePackages(from) require.NoError(t, err) + require.NotEmpty(t, pkgs, "expected some Slackware packages to test installation") require.NotEmpty(t, os.Getenv("ROOT"), "expected ROOT environment variable to be set") root := os.Getenv("ROOT") require.NotEqual(t, "/", root, "a test directory should be used for ROOT. All files there will be deleted") - _ = os.RemoveAll(root) - installFlags := DefaultInstallPkgFlags installFlags.chmod = false installFlags.chown = false + installFlags.Strict = true installFlags.SetEnvValues() removeFlags := DefaultRemovePkgFlags |