Skip to content

Commit ae518bc

Browse files
MagicalTuxclaude
andcommitted
fix: address lint warnings — check errors, export XattrBuildKey
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b26d87b commit ae518bc

3 files changed

Lines changed: 46 additions & 23 deletions

File tree

writer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,9 @@ func (w *Writer) writeXattrTable() error {
11621162
physOffset, offset := kvMeta.Position()
11631163
ref := (physOffset << 16) | uint64(offset)
11641164

1165-
kvMeta.Write(sets[i].kvData)
1165+
if _, err := kvMeta.Write(sets[i].kvData); err != nil {
1166+
return err
1167+
}
11661168

11671169
idEntries = append(idEntries, idEntry{
11681170
ref: ref,

writer_roundtrip_test.go

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -728,16 +728,20 @@ func TestRoundTripFragments(t *testing.T) {
728728
func TestRoundTripFragmentMixedSizes(t *testing.T) {
729729
blockSize := uint32(4096) // small block size for testing
730730
data := buildImage(t, []squashfs.WriterOption{squashfs.WithBlockSize(blockSize)}, func(w *squashfs.Writer) {
731-
// 1 byte — entirely in fragment
732-
w.AddFile("tiny.txt", []byte("x"), 0644)
733-
// blockSize-1 — entirely in fragment
734-
w.AddFile("almost_block.txt", bytes.Repeat([]byte("a"), int(blockSize)-1), 0644)
735-
// Exactly blockSize — full block, no fragment
736-
w.AddFile("exact_block.txt", bytes.Repeat([]byte("b"), int(blockSize)), 0644)
737-
// blockSize+1 — one full block + 1 byte fragment
738-
w.AddFile("block_plus_one.txt", bytes.Repeat([]byte("c"), int(blockSize)+1), 0644)
739-
// 2*blockSize+50 — two full blocks + 50 byte fragment
740-
w.AddFile("two_blocks_plus.txt", bytes.Repeat([]byte("d"), int(blockSize)*2+50), 0644)
731+
for _, tc := range []struct {
732+
name string
733+
data []byte
734+
}{
735+
{"tiny.txt", []byte("x")},
736+
{"almost_block.txt", bytes.Repeat([]byte("a"), int(blockSize)-1)},
737+
{"exact_block.txt", bytes.Repeat([]byte("b"), int(blockSize))},
738+
{"block_plus_one.txt", bytes.Repeat([]byte("c"), int(blockSize)+1)},
739+
{"two_blocks_plus.txt", bytes.Repeat([]byte("d"), int(blockSize)*2+50)},
740+
} {
741+
if err := w.AddFile(tc.name, tc.data, 0644); err != nil {
742+
t.Fatal(err)
743+
}
744+
}
741745
})
742746

743747
sb := openImage(t, data)
@@ -782,14 +786,22 @@ func TestCloneFile(t *testing.T) {
782786

783787
// Image with clone
784788
cloneData := buildImage(t, nil, func(w *squashfs.Writer) {
785-
w.AddFile("original.txt", content, 0644)
786-
w.CloneInode("clone.txt", "original.txt")
789+
if err := w.AddFile("original.txt", content, 0644); err != nil {
790+
t.Fatal(err)
791+
}
792+
if err := w.CloneInode("clone.txt", "original.txt"); err != nil {
793+
t.Fatal(err)
794+
}
787795
})
788796

789797
// Image without clone (two copies)
790798
noCloneData := buildImage(t, nil, func(w *squashfs.Writer) {
791-
w.AddFile("original.txt", content, 0644)
792-
w.AddFile("clone.txt", content, 0644)
799+
if err := w.AddFile("original.txt", content, 0644); err != nil {
800+
t.Fatal(err)
801+
}
802+
if err := w.AddFile("clone.txt", content, 0644); err != nil {
803+
t.Fatal(err)
804+
}
793805
})
794806

795807
t.Logf("With clone: %d bytes, without: %d bytes, saving: %d bytes",
@@ -818,12 +830,21 @@ func TestCloneFile(t *testing.T) {
818830

819831
func TestXattrRoundTrip(t *testing.T) {
820832
data := buildImage(t, nil, func(w *squashfs.Writer) {
821-
w.AddFile("file.txt", []byte("hello"), 0644)
822-
w.SetXattr("file.txt", "user.myattr", []byte("myvalue"))
823-
w.SetXattr("file.txt", "user.another", []byte("val2"))
824-
825-
w.AddDirectory("dir", 0755)
826-
w.SetXattr("dir", "user.dirattr", []byte("dirval"))
833+
if err := w.AddFile("file.txt", []byte("hello"), 0644); err != nil {
834+
t.Fatal(err)
835+
}
836+
if err := w.SetXattr("file.txt", "user.myattr", []byte("myvalue")); err != nil {
837+
t.Fatal(err)
838+
}
839+
if err := w.SetXattr("file.txt", "user.another", []byte("val2")); err != nil {
840+
t.Fatal(err)
841+
}
842+
if err := w.AddDirectory("dir", 0755); err != nil {
843+
t.Fatal(err)
844+
}
845+
if err := w.SetXattr("dir", "user.dirattr", []byte("dirval")); err != nil {
846+
t.Fatal(err)
847+
}
827848
})
828849

829850
sb := openImage(t, data)

xattr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func xattrParseKey(key string) (uint16, string, error) {
3131
return 0, "", fmt.Errorf("unknown xattr namespace: %s", key)
3232
}
3333

34-
// xattrBuildKey reconstructs a full key from type and name.
35-
func xattrBuildKey(typ uint16, name string) string {
34+
// XattrBuildKey reconstructs a full key from type and name.
35+
func XattrBuildKey(typ uint16, name string) string {
3636
if prefix, ok := xattrPrefixes[typ&0xFF]; ok {
3737
return prefix + name
3838
}

0 commit comments

Comments
 (0)