Skip to content

Commit

Permalink
chore: apply changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijie-yang committed Dec 2, 2024
1 parent cadc1d5 commit aa89a17
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 0 additions & 2 deletions internal/deb/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ func extractData(pkgReader io.ReadSeeker, options *ExtractOptions) error {
}
// Create the entry itself.
link := tarHeader.Linkname
// TODO: The first hard link in the tarball does not have tar.TypeLink flag.
// We need to update its fstutil.Entry.Link later.
if tarHeader.Typeflag == tar.TypeLink {
// A hard link requires the real path of the target file.
link = filepath.Join(options.TargetDir, link)
Expand Down
15 changes: 8 additions & 7 deletions internal/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ type RunOptions struct {
}

type pathData struct {
until setup.PathUntil
mutable bool
isHardLink bool
until setup.PathUntil
mutable bool
hardLink bool
}

type contentChecker struct {
Expand All @@ -44,7 +44,8 @@ type contentChecker struct {
func (cc *contentChecker) checkMutable(path string) error {
if !cc.knownPaths[path].mutable {
return fmt.Errorf("cannot write file which is not mutable: %s", path)
} else if cc.knownPaths[path].isHardLink { // mutable
}
if cc.knownPaths[path].hardLink {
return fmt.Errorf("cannot mutate a hard link: %s", path)
}
return nil
Expand Down Expand Up @@ -209,9 +210,9 @@ func Run(options *RunOptions) error {

if inSliceContents {
data := pathData{
mutable: mutable,
until: until,
isHardLink: entry.Mode.IsRegular() && entry.Link != "",
mutable: mutable,
until: until,
hardLink: entry.LinkType == fsutil.TypeHardLink,
}
addKnownPath(knownPaths, relPath, data)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/slicer/slicer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ var slicerTests = []slicerTest{{
},
error: `slice test-package_myslice: cannot mutate a hard link: /hardlink`,
}, {
summary: "Specifying mutability true for a hard link but not write to it is allowed",
summary: "Hard links can be marked as mutable, but not mutated",
slices: []setup.SliceKey{
{"test-package", "myslice"}},
pkgs: []*testutil.TestPackage{{
Expand Down

0 comments on commit aa89a17

Please sign in to comment.