aboutsummaryrefslogtreecommitdiffsponsor
diff options
context:
space:
mode:
authorSlack Coder <slackcoder@server.ky>2022-05-19 15:39:24 -0500
committerSlack Coder <slackcoder@server.ky>2022-05-20 15:06:50 -0500
commita1e7249e712bfc7bbcf6275bdd87f2343d60f81a (patch)
treea8827ba2b8701640bfdb4cbe6f148ad5055147cd
parent3026d40715e2758bc9ddfbd98acb558cfcba3c5d (diff)
downloadpkgtools-go-a1e7249e712bfc7bbcf6275bdd87f2343d60f81a.tar.xz
bail out on unknown package attributes
Be freindlier to the user by clearly communicating and refusing to install packages we do not know how to install. Add an environment variable allowing users to opt out and silently ignore errors if they so choose.
-rw-r--r--README.md13
-rw-r--r--archive.go17
-rw-r--r--installpkg.go23
-rw-r--r--removepkg_integration_test.go4
4 files changed, 48 insertions, 9 deletions
diff --git a/README.md b/README.md
index 2084198..8144a5d 100644
--- a/README.md
+++ b/README.md
@@ -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
+```
diff --git a/archive.go b/archive.go
index 6610936..76c16b8 100644
--- a/archive.go
+++ b/archive.go
@@ -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