Skip to content

Commit

Permalink
Move defer?
Browse files Browse the repository at this point in the history
  • Loading branch information
kipz committed Dec 19, 2023
1 parent 011f7b6 commit 655513d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
3 changes: 2 additions & 1 deletion metadata/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func (update *Updater) persistMetadata(roleName string, data []byte) error {
if err != nil {
return err
}
defer file.Close()

// write the data content to the temporary file
err = os.WriteFile(file.Name(), data, 0644)
if err != nil {
Expand All @@ -630,6 +630,7 @@ func (update *Updater) persistMetadata(roleName string, data []byte) error {
}
return err
}
defer file.Close()
// can't move/rename an open file on windows, so close it first
file.Close()
// if all okay, rename the temporary file to the desired one
Expand Down
6 changes: 0 additions & 6 deletions metadata/updater/updater_consistent_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@ func TestTopLevelRolesUpdateWithConsistentSnapshotDisabled(t *testing.T) {
updaterConfig, err := loadUpdaterConfig()
assert.NoError(t, err)
updater := initUpdater(updaterConfig)
if updater == nil {
t.Fatal("updater is nil")
}
// cleanup fetch tracker metadata
simulator.Sim.FetchTracker.Metadata = []simulator.FTMetadata{}
err = updater.Refresh()
if err != nil {
t.Fatal(err)
}
assert.NoError(t, err)

// metadata files are fetched with the expected version (or None)
Expand Down

0 comments on commit 655513d

Please sign in to comment.