Skip to content

Commit bae4554

Browse files
authored
fix: improve error when installing driver archive with subdirs (#330)
dbc currently can't install driver archives with subfolders but the error message the user gets could be improved. This isn't a major issue since we've been the ones doing all the packaging but others could run into this if they start creating driver archives. This change makes the reason for the error explicit.
1 parent 13068a7 commit bae4554

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

cmd/dbc/install_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package main
1616

1717
import (
18+
"archive/tar"
19+
"compress/gzip"
1820
"fmt"
1921
"os"
2022
"path/filepath"
@@ -411,3 +413,33 @@ func (suite *SubcommandTestSuite) TestInstallCompleteRegistryFailure() {
411413
suite.Contains(out, "connection timeout")
412414
suite.driverIsNotInstalled("test-driver-1")
413415
}
416+
417+
func (suite *SubcommandTestSuite) TestInstallDriverWithSubdirectories() {
418+
packageDir := suite.T().TempDir()
419+
packagePath := filepath.Join(packageDir, "driver-with-subdir.tar.gz")
420+
421+
f, err := os.Create(packagePath)
422+
suite.Require().NoError(err)
423+
gzw := gzip.NewWriter(f)
424+
tw := tar.NewWriter(gzw)
425+
426+
// Just add the subdir as the only entry
427+
err = tw.WriteHeader(&tar.Header{
428+
Name: "subdir/",
429+
Mode: 0755,
430+
Typeflag: tar.TypeDir,
431+
})
432+
suite.Require().NoError(err)
433+
434+
suite.Require().NoError(tw.Close())
435+
suite.Require().NoError(gzw.Close())
436+
suite.Require().NoError(f.Close())
437+
438+
// Should fail
439+
m := InstallCmd{Driver: packagePath, NoVerify: true}.
440+
GetModelCustom(baseModel{getDriverRegistry: getTestDriverRegistry, downloadPkg: downloadTestPkg})
441+
out := suite.runCmdErr(m)
442+
443+
// and return an error with this
444+
suite.Contains(out, "driver archives shouldn't contain subdirectories")
445+
}

config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ func InflateTarball(f *os.File, outDir string) (Manifest, error) {
267267
return m, fmt.Errorf("error reading tarball: %w", err)
268268
}
269269

270+
// Return a helpful error if an entry is a directory. dbc doesn't support
271+
// installing driver tarballs that contain directories.
272+
if hdr.Typeflag == tar.TypeDir {
273+
return m, fmt.Errorf("found a directory entry when trying to extract %s which isn't supported. driver archives shouldn't contain subdirectories", f.Name())
274+
}
275+
270276
if hdr.Name != "MANIFEST" {
271277
next, err := os.Create(filepath.Join(outDir, hdr.Name))
272278
if err != nil {

0 commit comments

Comments
 (0)