Skip to content

Commit

Permalink
Merge pull request #272 from tri-adam/set-prim-fix
Browse files Browse the repository at this point in the history
fix: set descriptor timestamp(s) in SetPrimPart
  • Loading branch information
tri-adam authored Mar 9, 2023
2 parents 5a9464b + 3d0d786 commit 868c239
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
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:
Expand Down
8 changes: 5 additions & 3 deletions pkg/sif/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
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.
Expand Down Expand Up @@ -326,7 +326,6 @@ func TestAddObject(t *testing.T) {
},
di: getDescriptorInput(t, DataGeneric, []byte{0xfa, 0xce}),
opts: []AddOpt{
OptAddDeterministic(),
OptAddWithTime(time.Unix(946702800, 0)),
},
},
Expand Down Expand Up @@ -505,7 +504,6 @@ func TestDeleteObject(t *testing.T) {
},
id: 1,
opts: []DeleteOpt{
OptDeleteDeterministic(),
OptDeleteWithTime(time.Unix(946702800, 0)),
},
},
Expand Down Expand Up @@ -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)),
},
},
Expand Down
Binary file modified pkg/sif/testdata/TestSetPrimPart/WithTime.golden
Binary file not shown.

0 comments on commit 868c239

Please sign in to comment.