Skip to content

Commit

Permalink
Merge pull request #217 from DrDaveD/pick-sylabs-2.15.1
Browse files Browse the repository at this point in the history
Update to sylabs/sif 2.15.1
  • Loading branch information
DrDaveD committed Dec 28, 2023
2 parents db72446 + ceb19fa commit ee8e90b
Show file tree
Hide file tree
Showing 25 changed files with 99 additions and 308 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/apptainer/sif/v2
go 1.20

require (
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c
github.com/google/go-containerregistry v0.17.0
github.com/google/uuid v1.5.0
github.com/sebdah/goldie/v2 v2.5.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs=
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX7IL/m9Y5LO+KQYv+t1CQOiFe6+SV2J7bE=
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
Expand Down
24 changes: 0 additions & 24 deletions internal/app/siftool/mount.go

This file was deleted.

24 changes: 0 additions & 24 deletions internal/app/siftool/unmount.go

This file was deleted.

83 changes: 30 additions & 53 deletions pkg/sif/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,51 +326,6 @@ func CreateContainerAtPath(path string, opts ...CreateOpt) (*FileImage, error) {
return f, nil
}

func zeroData(fimg *FileImage, descr *rawDescriptor) error {
// first, move to data object offset
if _, err := fimg.rw.Seek(descr.Offset, io.SeekStart); err != nil {
return err
}

var zero [4096]byte
n := descr.Size
upbound := int64(4096)
for {
if n < 4096 {
upbound = n
}

if _, err := fimg.rw.Write(zero[:upbound]); err != nil {
return err
}
n -= 4096
if n <= 0 {
break
}
}

return nil
}

func resetDescriptor(fimg *FileImage, index int) error {
// If we remove the primary partition, set the global header Arch field to HdrArchUnknown
// to indicate that the SIF file doesn't include a primary partition and no dependency
// on any architecture exists.
if fimg.rds[index].isPartitionOfType(PartPrimSys) {
fimg.h.Arch = hdrArchUnknown
}

offset := fimg.h.DescriptorsOffset + int64(index)*int64(binary.Size(fimg.rds[0]))

// first, move to descriptor offset
if _, err := fimg.rw.Seek(offset, io.SeekStart); err != nil {
return err
}

var emptyDesc rawDescriptor
return binary.Write(fimg.rw, binary.LittleEndian, emptyDesc)
}

// addOpts accumulates object add options.
type addOpts struct {
t time.Time
Expand Down Expand Up @@ -452,6 +407,26 @@ func (f *FileImage) isLast(d *rawDescriptor) bool {
return isLast
}

// zeroReader is an io.Reader that returns a stream of zero-bytes.
type zeroReader struct{}

func (zeroReader) Read(b []byte) (int, error) {
for i := range b {
b[i] = 0
}
return len(b), nil
}

// zero overwrites the data object described by d with a stream of zero bytes.
func (f *FileImage) zero(d *rawDescriptor) error {
if _, err := f.rw.Seek(d.Offset, io.SeekStart); err != nil {
return err
}

_, err := io.CopyN(f.rw, zeroReader{}, d.Size)
return err
}

// truncateAt truncates f at the start of the padded data object described by d.
func (f *FileImage) truncateAt(d *rawDescriptor) error {
start := d.Offset + d.Size - d.SizeWithPadding
Expand Down Expand Up @@ -535,7 +510,7 @@ func (f *FileImage) DeleteObject(id uint32, opts ...DeleteOpt) error {
}

if do.zero {
if err := zeroData(f, d); err != nil {
if err := f.zero(d); err != nil {
return fmt.Errorf("%w", err)
}
}
Expand All @@ -551,15 +526,17 @@ func (f *FileImage) DeleteObject(id uint32, opts ...DeleteOpt) error {
f.h.DescriptorsFree++
f.h.ModifiedAt = do.t.Unix()

index := 0
for i, od := range f.rds {
if od.ID == id {
index = i
break
}
// If we remove the primary partition, set the global header Arch field to HdrArchUnknown
// to indicate that the SIF file doesn't include a primary partition and no dependency
// on any architecture exists.
if d.isPartitionOfType(PartPrimSys) {
f.h.Arch = hdrArchUnknown
}

if err := resetDescriptor(f, index); err != nil {
// Reset rawDescripter with empty struct
*d = rawDescriptor{}

if err := f.writeDescriptors(); err != nil {
return fmt.Errorf("%w", err)
}

Expand Down
63 changes: 63 additions & 0 deletions pkg/sif/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,69 @@ func TestDeleteObject(t *testing.T) {
}
}

func TestDeleteObjectAndAddObject(t *testing.T) {
tests := []struct {
name string
id uint32
opts []DeleteOpt
}{
{
name: "Compact",
id: 2,
opts: []DeleteOpt{
OptDeleteCompact(true),
},
},
{
name: "NoCompact",
id: 2,
},
{
name: "Zero",
id: 2,
opts: []DeleteOpt{
OptDeleteZero(true),
},
},
{
name: "ZeroCompact",
id: 2,
opts: []DeleteOpt{
OptDeleteZero(true),
OptDeleteCompact(true),
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var b Buffer

f, err := CreateContainer(&b,
OptCreateDeterministic(),
OptCreateWithDescriptors(
getDescriptorInput(t, DataGeneric, []byte("abc")),
getDescriptorInput(t, DataGeneric, []byte("def")),
),
)
if err != nil {
t.Fatal(err)
}

if err := f.DeleteObject(tt.id, tt.opts...); err != nil {
t.Fatal(err)
}

if err := f.AddObject(getDescriptorInput(t, DataGeneric, []byte("ghi"))); err != nil {
t.Fatal(err)
}

g := goldie.New(t, goldie.WithTestNameForDir(true))
g.Assert(t, tt.name, b.Bytes())
})
}
}

func TestSetPrimPart(t *testing.T) {
tests := []struct {
name string
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 0 additions & 31 deletions pkg/siftool/mount.go

This file was deleted.

65 changes: 0 additions & 65 deletions pkg/siftool/mount_test.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/siftool/siftool.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,5 @@ func AddCommands(cmd *cobra.Command, opts ...CommandOpt) error {
c.getSetPrim(),
)

if c.opts.experimental {
cmd.AddCommand(c.getMount())
cmd.AddCommand(c.getUnmount())
}

return nil
}
6 changes: 1 addition & 5 deletions pkg/siftool/siftool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func makeTestSIF(t *testing.T, withDataObject bool) string {
return tf.Name()
}

//nolint:unparam
func runCommand(t *testing.T, cmd *cobra.Command, args []string, wantErr error) {
t.Helper()

Expand Down Expand Up @@ -123,11 +124,6 @@ func TestAddCommands(t *testing.T) {
name: "SetPrim",
args: []string{"help", "setprim"},
},
{
name: "Mount",
opts: []CommandOpt{OptWithExperimental(true)},
args: []string{"help", "mount"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Empty file.
10 changes: 0 additions & 10 deletions pkg/siftool/testdata/TestAddCommands/Mount/out.golden

This file was deleted.

This file was deleted.

0 comments on commit ee8e90b

Please sign in to comment.