Skip to content

Commit

Permalink
Update Atomic package
Browse files Browse the repository at this point in the history
Add docstring to fh.sync
Update the code to not use ioutil package.
  • Loading branch information
lhaig committed Nov 14, 2022
1 parent 869fcb6 commit a4be138
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/file/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func WriteAtomicWithPerms(path string, contents []byte, dirPerms, filePerms os.F
os.Remove(tempPath)
return err
}
// Commits the current state of the file to disk
if err := fh.Sync(); err != nil {
fh.Close()
os.Remove(tempPath)
Expand Down
5 changes: 2 additions & 3 deletions lib/file/atomic_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package file

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -13,7 +12,7 @@ import (
// tests that it just writes the file properly. I would love to test this
// better but I'm not sure how. -mitchellh
func TestWriteAtomic(t *testing.T) {
td, err := ioutil.TempDir("", "lib-file")
td, err := os.MkdirTemp("", "lib-file")
require.NoError(t, err)
defer os.RemoveAll(td)

Expand All @@ -25,7 +24,7 @@ func TestWriteAtomic(t *testing.T) {
require.NoError(t, WriteAtomic(path, expected))

// Read and verify
actual, err := ioutil.ReadFile(path)
actual, err := os.ReadFile(path)
require.NoError(t, err)
require.Equal(t, expected, actual)
}

0 comments on commit a4be138

Please sign in to comment.