Skip to content

Commit

Permalink
chore: use created time
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnetop committed Nov 25, 2023
1 parent 52f7fb4 commit 880220c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ module github.com/danielnetop/sn-export-to-folder

go 1.20

require (
github.com/djherbis/times v1.6.0
github.com/stretchr/testify v1.8.2
)
require github.com/stretchr/testify v1.8.2

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -12,8 +10,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
6 changes: 3 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func sanitizeName(filename string) string {
return filename
}

func updateTimes(path string, updatedAt time.Time, createdAt time.Time) error {
err := os.Chtimes(path, updatedAt, createdAt)
func updateTimes(path string, createdAt time.Time) error {
err := os.Chtimes(path, createdAt, createdAt)
if err != nil {
return errUpdatingTimes
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func createNoteAndUpdateTimes(note Note, notePath string) error {
return fmt.Errorf("%w - \"%s\"", err, note.Title)
}

err = updateTimes(notePath, note.UpdatedAt, note.CreatedAt)
err = updateTimes(notePath, note.CreatedAt)
if err != nil {
return fmt.Errorf("%w - \"%s\"", err, notePath)
}
Expand Down
8 changes: 3 additions & 5 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

"github.com/djherbis/times"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -703,14 +702,13 @@ func Test_updateTimes(t *testing.T) {
require.NoError(t, err)
}

assert.ErrorIs(t, tt.err, updateTimes(tt.path, tt.updatedAt, tt.createdAt))
assert.ErrorIs(t, tt.err, updateTimes(tt.path, tt.createdAt))

if tt.err == nil {
fileInfo, err := times.Stat(tt.path)
fileInfo, err := os.Stat(tt.path)
require.NoError(t, err)

assert.Equal(t, tt.updatedAt.UnixMilli(), fileInfo.AccessTime().UnixMilli())
assert.Equal(t, tt.createdAt.UnixMilli(), fileInfo.BirthTime().UnixMilli())
assert.True(t, tt.createdAt.Equal(fileInfo.ModTime()))
assert.NotEqual(t, fileInfoBeforeUpdate, fileInfo.ModTime())
}
})
Expand Down

0 comments on commit 880220c

Please sign in to comment.