Ensure base cache path exists before calculating disk cache capacity
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Apr 2020 10:29:49 +0000 (10:29 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Apr 2020 10:29:49 +0000 (10:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=209338

Reviewed by Adrian Perez de Castro.

The base cache path might not exist yet in Cache::open() since it's Storage::open() the one calling
FileSystem::makeAllDirectories() with the final cache directory. In such case, computeCapacity() fails because
FileSystem::getVolumeFreeSpace() needs an existing file.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::open):

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

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/NetworkCache.cpp

index f31ab69..11de4e3 100644 (file)
@@ -1,3 +1,17 @@
+2020-04-08  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        Ensure base cache path exists before calculating disk cache capacity
+        https://bugs.webkit.org/show_bug.cgi?id=209338
+
+        Reviewed by Adrian Perez de Castro.
+
+        The base cache path might not exist yet in Cache::open() since it's Storage::open() the one calling
+        FileSystem::makeAllDirectories() with the final cache directory. In such case, computeCapacity() fails because
+        FileSystem::getVolumeFreeSpace() needs an existing file.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::Cache::open):
+
 2020-04-08  Keith Rollin  <krollin@apple.com>
 
         Enable the use of XCBuild by default in Apple builds
index 72ba6bf..6ae78a2 100644 (file)
@@ -78,6 +78,9 @@ static size_t computeCapacity(CacheModel cacheModel, const String& cachePath)
 
 RefPtr<Cache> Cache::open(NetworkProcess& networkProcess, const String& cachePath, OptionSet<CacheOption> options, PAL::SessionID sessionID)
 {
+    if (!FileSystem::makeAllDirectories(cachePath))
+        return nullptr;
+
     auto capacity = computeCapacity(networkProcess.cacheModel(), cachePath);
     auto storage = Storage::open(cachePath, options.contains(CacheOption::TestingMode) ? Storage::Mode::AvoidRandomness : Storage::Mode::Normal, capacity);