Title: [287377] trunk
Revision
287377
Author
[email protected]
Date
2021-12-22 15:55:10 -0800 (Wed, 22 Dec 2021)

Log Message

WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
https://bugs.webkit.org/show_bug.cgi?id=234404

Reviewed by Youenn Fablet.

Source/WebKit:

createDirectoryAtURL returning false means directory cannot be created, but the cause can be that directory
already exists; so we should set exclude attribute on the directory no matter createDirectoryAtURL returns true
or false. Also, we can use existing FileSystem functions.

API test: WKWebView.LocalStorageDirectoryExcludedFromBackup

* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::excludeDirectoryFromBackup): Deleted.
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStore.h:

Source/WTF:

* wtf/FileSystem.cpp:
(WTF::FileSystemImpl::excludeFromBackup):
(WTF::FileSystemImpl::canExcludeFromBackup): Deleted.
* wtf/FileSystem.h:
* wtf/cocoa/FileSystemCocoa.mm:
(WTF::FileSystemImpl::excludeFromBackup):
* wtf/mac/FileSystemMac.mm:
(WTF::FileSystem::canExcludeFromBackup): Deleted.
(WTF::FileSystem::excludeFromBackup): Deleted.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (287376 => 287377)


--- trunk/Source/WTF/ChangeLog	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WTF/ChangeLog	2021-12-22 23:55:10 UTC (rev 287377)
@@ -1,3 +1,20 @@
+2021-12-22  Sihui Liu  <[email protected]>
+
+        WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
+        https://bugs.webkit.org/show_bug.cgi?id=234404
+
+        Reviewed by Youenn Fablet.
+
+        * wtf/FileSystem.cpp:
+        (WTF::FileSystemImpl::excludeFromBackup):
+        (WTF::FileSystemImpl::canExcludeFromBackup): Deleted.
+        * wtf/FileSystem.h:
+        * wtf/cocoa/FileSystemCocoa.mm:
+        (WTF::FileSystemImpl::excludeFromBackup):
+        * wtf/mac/FileSystemMac.mm:
+        (WTF::FileSystem::canExcludeFromBackup): Deleted.
+        (WTF::FileSystem::excludeFromBackup): Deleted.
+
 2021-12-22  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r287364.

Modified: trunk/Source/WTF/wtf/FileSystem.cpp (287376 => 287377)


--- trunk/Source/WTF/wtf/FileSystem.cpp	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WTF/wtf/FileSystem.cpp	2021-12-22 23:55:10 UTC (rev 287377)
@@ -305,16 +305,6 @@
 {
 }
 
-bool canExcludeFromBackup()
-{
-    return false;
-}
-
-bool excludeFromBackup(const String&)
-{
-    return false;
-}
-
 #endif
 
 MappedFileData::MappedFileData(const String& filePath, MappedFileMode mapMode, bool& success)
@@ -426,10 +416,17 @@
 #endif
 
 #if !PLATFORM(COCOA)
+
 String createTemporaryZipArchive(const String&)
 {
     return { };
 }
+
+bool excludeFromBackup(const String&)
+{
+    return false;
+}
+
 #endif
 
 MappedFileData mapToFile(const String& path, size_t bytesSize, Function<void(const Function<bool(Span<const uint8_t>)>&)>&& apply, PlatformFileHandle* outputHandle)

Modified: trunk/Source/WTF/wtf/FileSystem.h (287376 => 287377)


--- trunk/Source/WTF/wtf/FileSystem.h	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WTF/wtf/FileSystem.h	2021-12-22 23:55:10 UTC (rev 287377)
@@ -134,10 +134,8 @@
 WTF_EXPORT_PRIVATE std::optional<FileType> fileTypeFollowingSymlinks(const String&);
 
 WTF_EXPORT_PRIVATE void setMetadataURL(const String& path, const String& urlString, const String& referrer = { });
+WTF_EXPORT_PRIVATE bool excludeFromBackup(const String&); // Returns true if successful.
 
-bool canExcludeFromBackup(); // Returns true if any file can ever be excluded from backup.
-bool excludeFromBackup(const String&); // Returns true if successful.
-
 WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path); // Returns file names, not full paths.
 
 WTF_EXPORT_PRIVATE CString fileSystemRepresentation(const String&);

Modified: trunk/Source/WTF/wtf/cocoa/FileSystemCocoa.mm (287376 => 287377)


--- trunk/Source/WTF/wtf/cocoa/FileSystemCocoa.mm	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WTF/wtf/cocoa/FileSystemCocoa.mm	2021-12-22 23:55:10 UTC (rev 287377)
@@ -222,5 +222,16 @@
 }
 #endif
 
+bool excludeFromBackup(const String& path)
+{
+    NSError *error;
+    if (![[NSURL fileURLWithPath:(NSString *)path isDirectory:YES] setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:&error]) {
+        LOG_ERROR("Cannot exclude path '%s' from backup with error '%@'", path.utf8().data(), error.localizedDescription);
+        return false;
+    }
+
+    return true;
+}
+
 } // namespace FileSystemImpl
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/mac/FileSystemMac.mm (287376 => 287377)


--- trunk/Source/WTF/wtf/mac/FileSystemMac.mm	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WTF/wtf/mac/FileSystemMac.mm	2021-12-22 23:55:10 UTC (rev 287377)
@@ -57,18 +57,6 @@
     });
 }
 
-bool FileSystem::canExcludeFromBackup()
-{
-    return true;
-}
-
-bool FileSystem::excludeFromBackup(const String& path)
-{
-    // It is critical to pass FALSE for excludeByPath because excluding by path requires root privileges.
-    CSBackupSetItemExcluded(FileSystem::pathAsURL(path).get(), TRUE, FALSE);
-    return true;
-}
-
 } // namespace WTF
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit/ChangeLog (287376 => 287377)


--- trunk/Source/WebKit/ChangeLog	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WebKit/ChangeLog	2021-12-22 23:55:10 UTC (rev 287377)
@@ -1,3 +1,22 @@
+2021-12-22  Sihui Liu  <[email protected]>
+
+        WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
+        https://bugs.webkit.org/show_bug.cgi?id=234404
+
+        Reviewed by Youenn Fablet.
+
+        createDirectoryAtURL returning false means directory cannot be created, but the cause can be that directory 
+        already exists; so we should set exclude attribute on the directory no matter createDirectoryAtURL returns true
+        or false. Also, we can use existing FileSystem functions. 
+
+        API test: WKWebView.LocalStorageDirectoryExcludedFromBackup
+
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::excludeDirectoryFromBackup): Deleted.
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::parameters):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2021-12-22  Alex Christensen  <[email protected]>
 
         Re-enable CustomDisplayName and DefaultDisplayName API tests on Monterey

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm (287376 => 287377)


--- trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2021-12-22 23:55:10 UTC (rev 287377)
@@ -640,15 +640,4 @@
 #endif
 }
 
-#if PLATFORM(IOS_FAMILY)
-
-void WebsiteDataStore::excludeDirectoryFromBackup(const String& directory)
-{
-    NSURL *url = "" fileURLWithPath:(NSString *)directory isDirectory:YES];
-    if ([[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:nullptr])
-        [url setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
 }
-
-#endif
-
-}

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (287376 => 287377)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-12-22 23:55:10 UTC (rev 287377)
@@ -1914,12 +1914,13 @@
     auto localStorageDirectory = resolvedLocalStorageDirectory();
     if (!localStorageDirectory.isEmpty()) {
         parameters.localStorageDirectory = localStorageDirectory;
-#if PLATFORM(IOS_FAMILY)
-        excludeDirectoryFromBackup(localStorageDirectory);
-#endif
         // FIXME: SandboxExtension::createHandleForReadWriteDirectory resolves the directory, but that has already been done. Remove this duplicate work.
         if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(localStorageDirectory))
             parameters.localStorageDirectoryExtensionHandle = WTFMove(*handle);
+#if PLATFORM(IOS_FAMILY)
+        FileSystem::makeAllDirectories(localStorageDirectory);
+        FileSystem::excludeFromBackup(localStorageDirectory);
+#endif
     }
 
     auto cacheStorageDirectory = this->cacheStorageDirectory();

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (287376 => 287377)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2021-12-22 23:55:10 UTC (rev 287377)
@@ -372,10 +372,6 @@
 
     void countNonDefaultSessionSets(CompletionHandler<void(size_t)>&&);
 
-#if PLATFORM(IOS_FAMILY)
-    void excludeDirectoryFromBackup(const String& directory);
-#endif
-
 private:
     enum class ForceReinitialization : bool { No, Yes };
 #if ENABLE(APP_BOUND_DOMAINS)

Modified: trunk/Tools/ChangeLog (287376 => 287377)


--- trunk/Tools/ChangeLog	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Tools/ChangeLog	2021-12-22 23:55:10 UTC (rev 287377)
@@ -1,3 +1,13 @@
+2021-12-22  Sihui Liu  <[email protected]>
+
+        WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
+        https://bugs.webkit.org/show_bug.cgi?id=234404
+
+        Reviewed by Youenn Fablet.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
+        (TEST):
+
 2021-12-22  Alex Christensen  <[email protected]>
 
         Re-enable CustomDisplayName and DefaultDisplayName API tests on Monterey

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm (287376 => 287377)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm	2021-12-22 23:40:25 UTC (rev 287376)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm	2021-12-22 23:55:10 UTC (rev 287377)
@@ -39,6 +39,7 @@
 #import <WebKit/WebKit.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKUserStyleSheet.h>
+#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/text/WTFString.h>
 
@@ -452,3 +453,38 @@
     runTest(true);
     runTest(false);
 }
+
+#if PLATFORM(IOS_FAMILY)
+
+TEST(WKWebView, LocalStorageDirectoryExcludedFromBackup)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    RetainPtr<NSURL> url = "" websiteDataStore] _configuration] _webStorageDirectory];
+    // Create a directory and make it not excluded.
+    [[NSFileManager defaultManager] createDirectoryAtURL:url.get() withIntermediateDirectories:YES attributes:nil error:nullptr];
+    [url.get() setResourceValue:@NO forKey:NSURLIsExcludedFromBackupKey error:nil];
+    NSNumber *isDirectoryExcluded = nil;
+    EXPECT_TRUE([url.get() getResourceValue:&isDirectoryExcluded forKey:NSURLIsExcludedFromBackupKey error:nil]);
+    EXPECT_FALSE(isDirectoryExcluded.boolValue);
+
+    auto delegate = adoptNS([[LocalStorageNavigationDelegate alloc] init]);
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView setNavigationDelegate:delegate.get()];
+    didFinishNavigationBoolean = false;
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&didFinishNavigationBoolean);
+
+    bool finishedRunningScript = false;
+    [webView evaluateJavaScript:@"localStorage.getItem('key');" completionHandler: [&] (id result, NSError *) {
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+
+    // Create new url that has updated value.
+    url = "" websiteDataStore] _configuration] _webStorageDirectory];
+    EXPECT_TRUE([url.get() getResourceValue:&isDirectoryExcluded forKey:NSURLIsExcludedFromBackupKey error:nil]);
+    EXPECT_TRUE(isDirectoryExcluded.boolValue);
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to