From 6588427451c605ee00c8b1a9b6cba06724627ccb Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 20 May 2019 13:34:06 -0700 Subject: Fix incorrect tmpfs timestamp updates * Creation of files, directories (and other fs objects) in a directory should always update ctime. * Same for removal. * atime should not be updated on lookup, only readdir. I've also renamed some misleading functions that update mtime and ctime. PiperOrigin-RevId: 249115063 Change-Id: I30fa275fa7db96d01aa759ed64628c18bb3a7dc7 --- test/syscalls/linux/stat_times.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test') diff --git a/test/syscalls/linux/stat_times.cc b/test/syscalls/linux/stat_times.cc index 195c87ca5..68c0bef09 100644 --- a/test/syscalls/linux/stat_times.cc +++ b/test/syscalls/linux/stat_times.cc @@ -263,6 +263,40 @@ TEST(StatTimesTest, DirList) { CtimeEffect::Unchanged); } +// Creating a file in a directory changes mtime and ctime. +TEST(StatTimesTest, DirCreateFile) { + const TempPath dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); + + TempPath file; + auto fn = [&] { + file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileIn(dir.path())); + }; + CheckTimes(dir, fn, AtimeEffect::Unchanged, MtimeEffect::Changed, + CtimeEffect::Changed); +} + +// Creating a directory in a directory changes mtime and ctime. +TEST(StatTimesTest, DirCreateDir) { + const TempPath dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); + + TempPath dir2; + auto fn = [&] { + dir2 = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDirIn(dir.path())); + }; + CheckTimes(dir, fn, AtimeEffect::Unchanged, MtimeEffect::Changed, + CtimeEffect::Changed); +} + +// Removing a file from a directory changes mtime and ctime. +TEST(StatTimesTest, DirRemoveFile) { + const TempPath dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); + + TempPath file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileIn(dir.path())); + auto fn = [&] { file.reset(); }; + CheckTimes(dir, fn, AtimeEffect::Unchanged, MtimeEffect::Changed, + CtimeEffect::Changed); +} + } // namespace } // namespace testing -- cgit v1.2.3