diff --git a/internal/deb/extract.go b/internal/deb/extract.go index 16b1cecb..98d35d05 100644 --- a/internal/deb/extract.go +++ b/internal/deb/extract.go @@ -4,6 +4,7 @@ import ( "archive/tar" "bytes" "compress/gzip" + "errors" "fmt" "io" "io/fs" @@ -277,7 +278,7 @@ func extractData(pkgReader io.ReadSeeker, options *ExtractOptions) error { err := options.Create(extractInfos, createOptions) if err != nil { // Handle the hard link where its counterpart is not extracted - if tarHeader.Typeflag == tar.TypeLink && strings.HasPrefix(err.Error(), "link target does not exist") { + if tarHeader.Typeflag == tar.TypeLink && errors.Is(err, fsutil.LinkTargetNotExistError) { basePath := sanitizePath(tarHeader.Linkname) pendingHardlinks[basePath] = append(pendingHardlinks[basePath], PendingHardlink{ diff --git a/internal/fsutil/create.go b/internal/fsutil/create.go index 91b247b7..99b36a95 100644 --- a/internal/fsutil/create.go +++ b/internal/fsutil/create.go @@ -159,11 +159,13 @@ func createSymlink(o *CreateOptions) error { return os.Symlink(o.Link, o.Path) } +var LinkTargetNotExistError = fmt.Errorf("link target does not exist") + func createHardLink(o *CreateOptions) error { debugf("Creating hard link: %s => %s", o.Path, o.Link) linkInfo, err := os.Lstat(o.Link) if err != nil && os.IsNotExist(err) { - return &LinkTargetNotExistError{Link: o.Link} + return LinkTargetNotExistError } else if err != nil { return err } @@ -223,11 +225,3 @@ func (rp *writerProxy) Close() error { rp.entry.Size = rp.size return rp.inner.Close() } - -type LinkTargetNotExistError struct { - Link string -} - -func (e *LinkTargetNotExistError) Error() string { - return fmt.Sprintf("link target does not exist: %s", e.Link) -} diff --git a/internal/fsutil/create_test.go b/internal/fsutil/create_test.go index fc61a2cb..1ebb3a1b 100644 --- a/internal/fsutil/create_test.go +++ b/internal/fsutil/create_test.go @@ -130,7 +130,7 @@ var createTests = []createTest{{ hackopt: func(c *C, targetDir string, options *fsutil.CreateOptions) { options.Link = filepath.Join(targetDir, options.Link) }, - error: `link target does not exist: \/[^ ]*\/missing-file`, + error: `link target does not exist`, }, { summary: "Re-creating a duplicated hard link keeps the original link", options: fsutil.CreateOptions{