https://bugs.webkit.org/show_bug.cgi?id=144251
Reviewed by Martin Robinson.
The network process disk cache uses the creation time to compute a
worth value used to determine the order in which cached resources
are deleted when the cache is shrunk. In some operating systems
like Linux there's no st_birthtime in struct stat, but since cache
files are always created and deleted by us, we could use a custom
xattr to store and retrieve the creation time of cached resources.
* NetworkProcess/cache/NetworkCacheFileSystemPosix.h:
(WebKit::NetworkCache::fileTimes):
* NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
(WebKit::NetworkCache::IOChannel::IOChannel):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183532
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
2015-04-28 Carlos Garcia Campos <cgarcia@igalia.com>
+ [SOUP] Use xattrs to get/set the creation time of disk cache files
+ https://bugs.webkit.org/show_bug.cgi?id=144251
+
+ Reviewed by Martin Robinson.
+
+ The network process disk cache uses the creation time to compute a
+ worth value used to determine the order in which cached resources
+ are deleted when the cache is shrunk. In some operating systems
+ like Linux there's no st_birthtime in struct stat, but since cache
+ files are always created and deleted by us, we could use a custom
+ xattr to store and retrieve the creation time of cached resources.
+
+ * NetworkProcess/cache/NetworkCacheFileSystemPosix.h:
+ (WebKit::NetworkCache::fileTimes):
+ * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
+ (WebKit::NetworkCache::IOChannel::IOChannel):
+
+2015-04-28 Carlos Garcia Campos <cgarcia@igalia.com>
+
Network Cache: Do not create a SharedBuffer for mapped resources unless explicitly requested
https://bugs.webkit.org/show_bug.cgi?id=144337
#include <sys/time.h>
#include <wtf/text/CString.h>
+#if USE(SOUP)
+#include <wtf/gobject/GRefPtr.h>
+#endif
+
namespace WebKit {
namespace NetworkCache {
inline FileTimes fileTimes(const String& path)
{
+#if PLATFORM(COCOA)
struct stat fileInfo;
if (stat(WebCore::fileSystemRepresentation(path).data(), &fileInfo))
return { };
-#if PLATFORM(COCOA)
return { std::chrono::system_clock::from_time_t(fileInfo.st_birthtime), std::chrono::system_clock::from_time_t(fileInfo.st_mtime) };
-#else
- // FIXME: we need a way to get the creation time.
- return { std::chrono::system_clock::from_time_t(fileInfo.st_ctime), std::chrono::system_clock::from_time_t(fileInfo.st_mtime) };
+#endif
+#if 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));
+ if (!fileInfo)
+ return { };
+ const char* birthtimeString = g_file_info_get_attribute_string(fileInfo.get(), "xattr::birthtime");
+ return { std::chrono::system_clock::from_time_t(g_ascii_strtoull(birthtimeString, nullptr, 10)),
+ std::chrono::system_clock::from_time_t(g_file_info_get_attribute_uint64(fileInfo.get(), "time::modified")) };
#endif
}
#if ENABLE(NETWORK_CACHE)
#include "NetworkCacheFileSystemPosix.h"
+#include <wtf/gobject/GUniquePtr.h>
namespace WebKit {
namespace NetworkCache {
auto path = WebCore::fileSystemRepresentation(filePath);
GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.data()));
switch (m_type) {
- case Type::Create:
+ case Type::Create: {
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);
+ 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);
break;
+ }
case Type::Write: {
m_ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr));
ASSERT(m_ioStream);