Title: [277499] trunk
Revision
277499
Author
[email protected]
Date
2021-05-14 11:26:20 -0700 (Fri, 14 May 2021)

Log Message

Introduce FileSystem::updateFileModificationTime()
https://bugs.webkit.org/show_bug.cgi?id=225810

Reviewed by Darin Adler.

Source/WebKit:

Call the new FileSystem::updateFileModificationTime() API to modify the
file modification time instead of having low-level platform-specific
file system code at the WebKit2 layer.

* NetworkProcess/cache/NetworkCacheFileSystem.cpp:
(WebKit::NetworkCache::updateFileModificationTimeIfNeeded):

Source/WTF:

Introduce FileSystem::updateFileModificationTime() to update the modification time of a
file. The implementation is cross-platform and relies on std::filesystem. It allows us
to replace platform-specific code that we had at the WebKit2 layer.

* wtf/FileSystem.cpp:
(WTF::FileSystemImpl::updateFileModificationTime):
* wtf/FileSystem.h:

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WTF/FileSystem.cpp:
(TestWebKitAPI::TEST_F):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (277498 => 277499)


--- trunk/Source/WTF/ChangeLog	2021-05-14 17:54:23 UTC (rev 277498)
+++ trunk/Source/WTF/ChangeLog	2021-05-14 18:26:20 UTC (rev 277499)
@@ -1,5 +1,20 @@
 2021-05-14  Chris Dumez  <[email protected]>
 
+        Introduce FileSystem::updateFileModificationTime()
+        https://bugs.webkit.org/show_bug.cgi?id=225810
+
+        Reviewed by Darin Adler.
+
+        Introduce FileSystem::updateFileModificationTime() to update the modification time of a
+        file. The implementation is cross-platform and relies on std::filesystem. It allows us
+        to replace platform-specific code that we had at the WebKit2 layer.
+
+        * wtf/FileSystem.cpp:
+        (WTF::FileSystemImpl::updateFileModificationTime):
+        * wtf/FileSystem.h:
+
+2021-05-14  Chris Dumez  <[email protected]>
+
         Drop unused FileSystem::homeDirectoryPath()
         https://bugs.webkit.org/show_bug.cgi?id=225808
 

Modified: trunk/Source/WTF/wtf/FileSystem.cpp (277498 => 277499)


--- trunk/Source/WTF/wtf/FileSystem.cpp	2021-05-14 17:54:23 UTC (rev 277498)
+++ trunk/Source/WTF/wtf/FileSystem.cpp	2021-05-14 18:26:20 UTC (rev 277499)
@@ -686,6 +686,13 @@
     return toWallTime(modificationTime);
 }
 
+bool updateFileModificationTime(const String& path)
+{
+    std::error_code ec;
+    std::filesystem::last_write_time(toStdFileSystemPath(path), std::filesystem::file_time_type::clock::now(), ec);
+    return !ec;
+}
+
 enum class ShouldFollowSymbolicLinks { No, Yes };
 static Optional<FileMetadata> fileMetadataPotentiallyFollowingSymlinks(const String& path, ShouldFollowSymbolicLinks shouldFollowSymbolicLinks)
 {

Modified: trunk/Source/WTF/wtf/FileSystem.h (277498 => 277499)


--- trunk/Source/WTF/wtf/FileSystem.h	2021-05-14 17:54:23 UTC (rev 277498)
+++ trunk/Source/WTF/wtf/FileSystem.h	2021-05-14 18:26:20 UTC (rev 277499)
@@ -114,6 +114,7 @@
 WTF_EXPORT_PRIVATE Optional<uint64_t> fileSize(const String&);
 WTF_EXPORT_PRIVATE Optional<uint64_t> fileSize(PlatformFileHandle);
 WTF_EXPORT_PRIVATE Optional<WallTime> getFileModificationTime(const String&);
+WTF_EXPORT_PRIVATE bool updateFileModificationTime(const String& path); // Sets modification time to now.
 WTF_EXPORT_PRIVATE Optional<WallTime> getFileCreationTime(const String&); // Not all platforms store file creation time.
 WTF_EXPORT_PRIVATE Optional<FileMetadata> fileMetadata(const String& path);
 WTF_EXPORT_PRIVATE Optional<FileMetadata> fileMetadataFollowingSymlinks(const String& path);

Modified: trunk/Source/WebKit/ChangeLog (277498 => 277499)


--- trunk/Source/WebKit/ChangeLog	2021-05-14 17:54:23 UTC (rev 277498)
+++ trunk/Source/WebKit/ChangeLog	2021-05-14 18:26:20 UTC (rev 277499)
@@ -1,3 +1,17 @@
+2021-05-14  Chris Dumez  <[email protected]>
+
+        Introduce FileSystem::updateFileModificationTime()
+        https://bugs.webkit.org/show_bug.cgi?id=225810
+
+        Reviewed by Darin Adler.
+
+        Call the new FileSystem::updateFileModificationTime() API to modify the
+        file modification time instead of having low-level platform-specific
+        file system code at the WebKit2 layer.
+
+        * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
+        (WebKit::NetworkCache::updateFileModificationTimeIfNeeded):
+
 2021-05-14  Alex Christensen  <[email protected]>
 
         Resource Timing: secureConnectionStart == 0 when a connection is re-used

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp (277498 => 277499)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp	2021-05-14 17:54:23 UTC (rev 277498)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp	2021-05-14 18:26:20 UTC (rev 277499)
@@ -96,18 +96,7 @@
         if (WallTime::now() - times.modification < 1_h)
             return;
     }
-#if !OS(WINDOWS)
-    // This really updates both the access time and the modification time.
-    utimes(FileSystem::fileSystemRepresentation(path).data(), nullptr);
-#else
-    FILETIME time;
-    GetSystemTimeAsFileTime(&time);
-    auto file = CreateFile(path.wideCharacters().data(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
-    if (file == INVALID_HANDLE_VALUE)
-        return;
-    SetFileTime(file, &time, &time, &time);
-    CloseHandle(file);
-#endif
+    FileSystem::updateFileModificationTime(path);
 }
 
 }

Modified: trunk/Tools/ChangeLog (277498 => 277499)


--- trunk/Tools/ChangeLog	2021-05-14 17:54:23 UTC (rev 277498)
+++ trunk/Tools/ChangeLog	2021-05-14 18:26:20 UTC (rev 277499)
@@ -1,3 +1,15 @@
+2021-05-14  Chris Dumez  <[email protected]>
+
+        Introduce FileSystem::updateFileModificationTime()
+        https://bugs.webkit.org/show_bug.cgi?id=225810
+
+        Reviewed by Darin Adler.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WTF/FileSystem.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2021-05-14  Jonathan Bedard  <[email protected]>
 
         [run-api-tests] Use Python 3 (Part 2)

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp (277498 => 277499)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp	2021-05-14 17:54:23 UTC (rev 277498)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp	2021-05-14 18:26:20 UTC (rev 277499)
@@ -741,6 +741,27 @@
     });
 }
 
+TEST_F(FileSystemTest, updateFileModificationTime)
+{
+    auto modificationTime = FileSystem::getFileModificationTime(tempFilePath());
+    ASSERT_TRUE(!!modificationTime);
+
+    unsigned timeout = 0;
+    while (*modificationTime >= WallTime::now() && ++timeout < 20)
+        TestWebKitAPI::Util::sleep(0.1);
+    EXPECT_LT(modificationTime->secondsSinceEpoch().value(), WallTime::now().secondsSinceEpoch().value());
+
+    TestWebKitAPI::Util::sleep(1);
+
+    EXPECT_TRUE(FileSystem::updateFileModificationTime(tempFilePath()));
+    auto newModificationTime = FileSystem::getFileModificationTime(tempFilePath());
+    ASSERT_TRUE(!!newModificationTime);
+    EXPECT_GT(newModificationTime->secondsSinceEpoch().value(), modificationTime->secondsSinceEpoch().value());
+
+    auto doesNotExistPath = FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "does-not-exist");
+    EXPECT_FALSE(FileSystem::updateFileModificationTime(doesNotExistPath));
+}
+
 TEST_F(FileSystemTest, pathFileName)
 {
     auto testPath = FileSystem::pathByAppendingComponents(tempEmptyFolderPath(), { "subfolder", "filename.txt" });
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to