summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2018-11-26 16:23:23 +0100
committerPaweł Gronowski <pawel.gronowski@docker.com>2023-01-03 16:57:04 +0100
commit01fd23b6259642b99df5a033c1721a8d15becfb7 (patch)
tree44eaf4269d5906fab6710678bea562ffe2b96599
parentf5106148e333be4ad92fc6c9b9a30b0ff1e96f8d (diff)
downloaddocker-01fd23b6259642b99df5a033c1721a8d15becfb7.tar.gz
Fix volume CreatedAt being altered on initialization
The CreatedAt date was determined from the volume's `_data` directory (`/var/lib/docker/volumes/<volumename>/_data`). However, when initializing a volume, this directory is updated, causing the date to change. Instead of using the `_data` directory, use its parent directory, which is not updated afterwards, and should reflect the time that the volume was created. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
-rw-r--r--integration/volume/volume_test.go16
-rw-r--r--volume/local/local_unix.go2
-rw-r--r--volume/local/local_windows.go2
3 files changed, 18 insertions, 2 deletions
diff --git a/integration/volume/volume_test.go b/integration/volume/volume_test.go
index 6f3a4c64ad..87392620a4 100644
--- a/integration/volume/volume_test.go
+++ b/integration/volume/volume_test.go
@@ -3,6 +3,7 @@ package volume
import (
"context"
"net/http"
+ "os"
"path/filepath"
"strings"
"testing"
@@ -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
diff --git a/volume/local/local_unix.go b/volume/local/local_unix.go
index 051aef7a1e..2db5f8ef09 100644
--- a/volume/local/local_unix.go
+++ b/volume/local/local_unix.go
@@ -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
}
diff --git a/volume/local/local_windows.go b/volume/local/local_windows.go
index 8231a583f2..43b89b3cb1 100644
--- a/volume/local/local_windows.go
+++ b/volume/local/local_windows.go
@@ -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
}