Skip to content

Commit

Permalink
Merge pull request #44719 from vvoland/fix-volume-createdat
Browse files Browse the repository at this point in the history
Fix volume CreatedAt being altered on initialization
  • Loading branch information
thaJeztah committed Jan 3, 2023
2 parents b9fe30d + 01fd23b commit fcb5245
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions integration/volume/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package volume
import (
"context"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -104,6 +105,21 @@ func TestVolumesInspect(t *testing.T) {
createdAt, err := time.Parse(time.RFC3339, strings.TrimSpace(inspected.CreatedAt))
assert.NilError(t, err)
assert.Check(t, createdAt.Unix()-now.Unix() < 60, "CreatedAt (%s) exceeds creation time (%s) 60s", createdAt, now)

// update atime and mtime for the "_data" directory (which would happen during volume initialization)
modifiedAt := time.Now().Local().Add(5 * time.Hour)
err = os.Chtimes(inspected.Mountpoint, modifiedAt, modifiedAt)
assert.NilError(t, err)

inspected, err = client.VolumeInspect(ctx, vol.Name)
assert.NilError(t, err)

createdAt2, err := time.Parse(time.RFC3339, strings.TrimSpace(inspected.CreatedAt))
assert.NilError(t, err)

// Check that CreatedAt didn't change after updating atime and mtime of the "_data" directory
// Related issue: #38274
assert.Equal(t, createdAt, createdAt2)
}

// TestVolumesInvalidJSON tests that POST endpoints that expect a body return
Expand Down
2 changes: 1 addition & 1 deletion volume/local/local_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (v *localVolume) unmount() error {
}

func (v *localVolume) CreatedAt() (time.Time, error) {
fileInfo, err := os.Stat(v.path)
fileInfo, err := os.Stat(v.rootPath)
if err != nil {
return time.Time{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion volume/local/local_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (v *localVolume) postMount() error {
}

func (v *localVolume) CreatedAt() (time.Time, error) {
fileInfo, err := os.Stat(v.path)
fileInfo, err := os.Stat(v.rootPath)
if err != nil {
return time.Time{}, err
}
Expand Down

0 comments on commit fcb5245

Please sign in to comment.