From c2c1d1206ec18b6220c62cb67189ce8a86b20708 Mon Sep 17 00:00:00 2001 From: KastenMike <93532247+KastenMike@users.noreply.github.com> Date: Mon, 10 Jan 2022 11:50:49 +0100 Subject: [PATCH 1/2] add modTime on folder creation --- mem/file.go | 2 +- memmap_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mem/file.go b/mem/file.go index 5a20730c..5ef8b6a3 100644 --- a/mem/file.go +++ b/mem/file.go @@ -71,7 +71,7 @@ func CreateFile(name string) *FileData { } func CreateDir(name string) *FileData { - return &FileData{name: name, memDir: &DirMap{}, dir: true} + return &FileData{name: name, memDir: &DirMap{}, dir: true, modtime: time.Now()} } func ChangeFileName(f *FileData, newname string) { diff --git a/memmap_test.go b/memmap_test.go index 627b1067..819def8d 100644 --- a/memmap_test.go +++ b/memmap_test.go @@ -450,6 +450,9 @@ func TestMemFsMkdirAllMode(t *testing.T) { if !info.Mode().IsDir() { t.Error("/a: mode is not directory") } + if !info.ModTime().After(time.Now().Add(-1 * time.Hour)) { + t.Errorf("/a: mod time not set, got %s", info.Mode()) + } if info.Mode() != os.FileMode(os.ModeDir|0755) { t.Errorf("/a: wrong permissions, expected drwxr-xr-x, got %s", info.Mode()) } @@ -463,6 +466,9 @@ func TestMemFsMkdirAllMode(t *testing.T) { if info.Mode() != os.FileMode(os.ModeDir|0755) { t.Errorf("/a/b: wrong permissions, expected drwxr-xr-x, got %s", info.Mode()) } + if !info.ModTime().After(time.Now().Add(-1 * time.Hour)) { + t.Errorf("/a/b: mod time not set, got %s", info.Mode()) + } info, err = fs.Stat("/a/b/c") if err != nil { t.Fatal(err) @@ -473,6 +479,9 @@ func TestMemFsMkdirAllMode(t *testing.T) { if info.Mode() != os.FileMode(os.ModeDir|0755) { t.Errorf("/a/b/c: wrong permissions, expected drwxr-xr-x, got %s", info.Mode()) } + if !info.ModTime().After(time.Now().Add(-1 * time.Hour)) { + t.Errorf("/a/b/c: mod time not set, got %s", info.Mode()) + } } // MkdirAll does not change permissions of already-existing directories From 94409215e40b4f08b4f286b854adf4285cea284c Mon Sep 17 00:00:00 2001 From: KastenMike <93532247+KastenMike@users.noreply.github.com> Date: Mon, 10 Jan 2022 12:00:43 +0100 Subject: [PATCH 2/2] fix actual value in test --- memmap_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/memmap_test.go b/memmap_test.go index 819def8d..881a61bc 100644 --- a/memmap_test.go +++ b/memmap_test.go @@ -451,7 +451,7 @@ func TestMemFsMkdirAllMode(t *testing.T) { t.Error("/a: mode is not directory") } if !info.ModTime().After(time.Now().Add(-1 * time.Hour)) { - t.Errorf("/a: mod time not set, got %s", info.Mode()) + t.Errorf("/a: mod time not set, got %s", info.ModTime()) } if info.Mode() != os.FileMode(os.ModeDir|0755) { t.Errorf("/a: wrong permissions, expected drwxr-xr-x, got %s", info.Mode()) @@ -467,7 +467,7 @@ func TestMemFsMkdirAllMode(t *testing.T) { t.Errorf("/a/b: wrong permissions, expected drwxr-xr-x, got %s", info.Mode()) } if !info.ModTime().After(time.Now().Add(-1 * time.Hour)) { - t.Errorf("/a/b: mod time not set, got %s", info.Mode()) + t.Errorf("/a/b: mod time not set, got %s", info.ModTime()) } info, err = fs.Stat("/a/b/c") if err != nil { @@ -480,7 +480,7 @@ func TestMemFsMkdirAllMode(t *testing.T) { t.Errorf("/a/b/c: wrong permissions, expected drwxr-xr-x, got %s", info.Mode()) } if !info.ModTime().After(time.Now().Add(-1 * time.Hour)) { - t.Errorf("/a/b/c: mod time not set, got %s", info.Mode()) + t.Errorf("/a/b/c: mod time not set, got %s", info.ModTime()) } }