Skip to content

Commit

Permalink
correct small typos left from review
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Dec 5, 2024
1 parent 3031298 commit 8a65d8a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/manifest/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var sampleFile = fsutil.Entry{
Link: "",
}

var sampleSymLink = fsutil.Entry{
var sampleSymlink = fsutil.Entry{
Path: "/base/example-link",
Mode: fs.ModeSymlink | 0777,
SHA256: "example-file_hash",
Expand Down Expand Up @@ -111,7 +111,7 @@ var reportTests = []struct {
}},
}, {
summary: "Regular file link",
add: []sliceAndEntry{{entry: sampleSymLink, slice: oneSlice}},
add: []sliceAndEntry{{entry: sampleSymlink, slice: oneSlice}},
expected: map[string]manifest.ReportEntry{
"/example-link": {
Path: "/example-link",
Expand Down
3 changes: 2 additions & 1 deletion internal/testutil/nopcloser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
)

// readSeekNopCloser is an io.ReadSeeker that does nothing on Close.
// It is an extension of io.NopCloser that also implements io.Seeker.
type readSeekNopCloser struct {
io.ReadSeeker
}

func (readSeekNopCloser) Close() error { return nil }

// ReadSeekNopCloser is an extension of io.NopCloser that also implements
// io.Seeker.
func ReadSeekNopCloser(r io.ReadSeeker) io.ReadSeekCloser {
return readSeekNopCloser{r}
}
13 changes: 5 additions & 8 deletions internal/testutil/treedump.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,34 @@ func TreeDump(dir string) map[string]string {
if finfo.Mode()&fs.ModeSticky != 0 {
fperm |= 01000
}
var resultEntry string
var entry string
switch ftype {
case fs.ModeDir:
path = "/" + path + "/"
resultEntry = fmt.Sprintf("dir %#o", fperm)
entry = fmt.Sprintf("dir %#o", fperm)
case fs.ModeSymlink:
lpath, err := os.Readlink(fpath)
if err != nil {
return err
}
path = "/" + path
resultEntry = fmt.Sprintf("symlink %s", lpath)
entry = fmt.Sprintf("symlink %s", lpath)
case 0: // Regular
data, err := os.ReadFile(fpath)
if err != nil {
return fmt.Errorf("cannot read file: %w", err)
}
var entry string
if len(data) == 0 {
entry = fmt.Sprintf("file %#o empty", fperm)
} else {
sum := sha256.Sum256(data)
entry = fmt.Sprintf("file %#o %.4x", fperm, sum)
}
path = "/" + path
resultEntry = entry
default:
return fmt.Errorf("unknown file type %d: %s", ftype, fpath)
}
result[path] = resultEntry
result[path] = entry
if ftype != fs.ModeDir {
stat, ok := finfo.Sys().(*syscall.Stat_t)
if !ok {
Expand All @@ -82,8 +80,7 @@ func TreeDump(dir string) map[string]string {

// Append identifiers to paths who share an inode e.g. hard links.
for i := 0; i < len(inodes); i++ {
paths := pathsByInodes[inodes[i]]
for _, path := range paths {
for _, path := range pathsByInodes[inodes[i]] {
result[path] = fmt.Sprintf("%s <%d>", result[path], i+1)
}
}
Expand Down

0 comments on commit 8a65d8a

Please sign in to comment.