Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set descriptor timestamp(s) in SetPrimPart #272

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LICENSE

Copyright (c) 2018-2022, Sylabs Inc. All rights reserved.
Copyright (c) 2018-2023, Sylabs Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
8 changes: 5 additions & 3 deletions pkg/sif/create.go
Original file line number Diff line number Diff line change
@@ -636,9 +636,6 @@ func (f *FileImage) SetPrimPart(id uint32, opts ...SetOpt) error {
if err != nil && !errors.Is(err, ErrObjectNotFound) {
return fmt.Errorf("%w", err)
}

f.h.Arch = getSIFArch(arch)

extra := partition{
Fstype: fs,
Parttype: PartPrimSys,
@@ -649,6 +646,8 @@ func (f *FileImage) SetPrimPart(id uint32, opts ...SetOpt) error {
return fmt.Errorf("%w", err)
}

descr.ModifiedAt = so.t.Unix()

if olddescr != nil {
oldfs, _, oldarch, err := olddescr.getPartitionMetadata()
if err != nil {
@@ -664,12 +663,15 @@ func (f *FileImage) SetPrimPart(id uint32, opts ...SetOpt) error {
if err := olddescr.setExtra(oldextra); err != nil {
return fmt.Errorf("%w", err)
}

olddescr.ModifiedAt = so.t.Unix()
}

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

f.h.Arch = getSIFArch(arch)
f.h.ModifiedAt = so.t.Unix()

if err := f.writeHeader(); err != nil {
12 changes: 6 additions & 6 deletions pkg/sif/create_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2023, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE file distributed with the sources of this project regarding your
// rights to use or distribute this software.
@@ -326,7 +326,6 @@ func TestAddObject(t *testing.T) {
},
di: getDescriptorInput(t, DataGeneric, []byte{0xfa, 0xce}),
opts: []AddOpt{
OptAddDeterministic(),
OptAddWithTime(time.Unix(946702800, 0)),
},
},
@@ -505,7 +504,6 @@ func TestDeleteObject(t *testing.T) {
},
id: 1,
opts: []DeleteOpt{
OptDeleteDeterministic(),
OptDeleteWithTime(time.Unix(946702800, 0)),
},
},
@@ -571,13 +569,15 @@ func TestSetPrimPart(t *testing.T) {
OptCreateDeterministic(),
OptCreateWithDescriptors(
getDescriptorInput(t, DataPartition, []byte{0xfa, 0xce},
OptPartitionMetadata(FsRaw, PartSystem, "386"),
OptPartitionMetadata(FsRaw, PartPrimSys, "386"),
),
getDescriptorInput(t, DataPartition, []byte{0xfe, 0xed},
OptPartitionMetadata(FsRaw, PartSystem, "amd64"),
),
),
},
id: 1,
id: 2,
opts: []SetOpt{
OptSetDeterministic(),
OptSetWithTime(time.Unix(946702800, 0)),
},
},
Binary file modified pkg/sif/testdata/TestSetPrimPart/WithTime.golden
Binary file not shown.