[SOUP] Use st_birthtime to get creation time of files on systems support it
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 May 2015 16:37:11 +0000 (16:37 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 May 2015 16:37:11 +0000 (16:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144989

Patch by Ting-Wei Lan <lantw44@gmail.com> on 2015-05-19
Reviewed by Carlos Garcia Campos.

Source/WebKit2:

FreeBSD and NetBSD have either st_birthtime field or compatiblity macro
with the same name in stat. It is better to use it instead of manually
setting xattr, which is unreliable because both operating systems and
file systems support are required.

* NetworkProcess/cache/NetworkCacheFileSystemPosix.h:
(WebKit::NetworkCache::fileTimes):
* NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
(WebKit::NetworkCache::IOChannel::IOChannel):

Source/WTF:

Define HAVE(STAT_BIRTHTIME) as 1 on operating systems supporting
getting creation time of files using st_birthtime in stat.

* wtf/Platform.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184567 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h
Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp

index 22140e8..c54bd41 100644 (file)
@@ -1,3 +1,15 @@
+2015-05-19  Ting-Wei Lan  <lantw44@gmail.com>
+
+        [SOUP] Use st_birthtime to get creation time of files on systems support it
+        https://bugs.webkit.org/show_bug.cgi?id=144989
+
+        Reviewed by Carlos Garcia Campos.
+
+        Define HAVE(STAT_BIRTHTIME) as 1 on operating systems supporting
+        getting creation time of files using st_birthtime in stat.
+
+        * wtf/Platform.h:
+
 2015-05-19  Chris Dumez  <cdumez@apple.com>
 
         Mark static variables as const when possible
index 87594cb..a598474 100644 (file)
 #endif
 #endif
 
+#if OS(DARWIN) || OS(FREEBSD) || OS(NETBSD)
+#define HAVE_STAT_BIRTHTIME 1
+#endif
+
 #if !OS(WINDOWS) && !OS(SOLARIS)
 #define HAVE_TM_GMTOFF 1
 #define HAVE_TM_ZONE 1
index 4d8ce46..15a3c75 100644 (file)
@@ -1,3 +1,20 @@
+2015-05-19  Ting-Wei Lan  <lantw44@gmail.com>
+
+        [SOUP] Use st_birthtime to get creation time of files on systems support it
+        https://bugs.webkit.org/show_bug.cgi?id=144989
+
+        Reviewed by Carlos Garcia Campos.
+
+        FreeBSD and NetBSD have either st_birthtime field or compatiblity macro
+        with the same name in stat. It is better to use it instead of manually
+        setting xattr, which is unreliable because both operating systems and
+        file systems support are required.
+
+        * NetworkProcess/cache/NetworkCacheFileSystemPosix.h:
+        (WebKit::NetworkCache::fileTimes):
+        * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
+        (WebKit::NetworkCache::IOChannel::IOChannel):
+
 2015-05-19  Chris Dumez  <cdumez@apple.com>
 
         Mark static variables as const when possible
index ba5e498..875022c 100644 (file)
@@ -77,13 +77,12 @@ struct FileTimes {
 
 inline FileTimes fileTimes(const String& path)
 {
-#if PLATFORM(COCOA)
+#if HAVE(STAT_BIRTHTIME)
     struct stat fileInfo;
     if (stat(WebCore::fileSystemRepresentation(path).data(), &fileInfo))
         return { };
     return { std::chrono::system_clock::from_time_t(fileInfo.st_birthtime), std::chrono::system_clock::from_time_t(fileInfo.st_mtime) };
-#endif
-#if USE(SOUP)
+#elif USE(SOUP)
     // There's no st_birthtime in some operating systems like Linux, so we use xattrs to set/get the creation time.
     GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(WebCore::fileSystemRepresentation(path).data()));
     GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(file.get(), "xattr::birthtime,time::modified", G_FILE_QUERY_INFO_NONE, nullptr, nullptr));
index 591022c..83c797a 100644 (file)
@@ -49,8 +49,10 @@ IOChannel::IOChannel(const String& filePath, Type type)
         g_file_delete(file.get(), nullptr, nullptr);
         m_outputStream = adoptGRef(G_OUTPUT_STREAM(g_file_create(file.get(), static_cast<GFileCreateFlags>(G_FILE_CREATE_PRIVATE), nullptr, nullptr)));
         ASSERT(m_outputStream);
+#if !HAVE(STAT_BIRTHTIME)
         GUniquePtr<char> birthtimeString(g_strdup_printf("%" G_GUINT64_FORMAT, std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())));
         g_file_set_attribute_string(file.get(), "xattr::birthtime", birthtimeString.get(), G_FILE_QUERY_INFO_NONE, nullptr, nullptr);
+#endif
         break;
     }
     case Type::Write: {