Title: [287639] branches/safari-613.1.12.1-branch
Revision
287639
Author
repst...@apple.com
Date
2022-01-05 11:19:31 -0800 (Wed, 05 Jan 2022)

Log Message

Cherry-pick r287377. rdar://problem/86829012

    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):

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

Modified Paths

Diff

Modified: branches/safari-613.1.12.1-branch/Source/WTF/ChangeLog (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WTF/ChangeLog	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WTF/ChangeLog	2022-01-05 19:19:31 UTC (rev 287639)
@@ -1,3 +1,62 @@
+2022-01-05  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r287377. rdar://problem/86829012
+
+    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):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-12-22  Sihui Liu  <sihui_...@apple.com>
+
+            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-16  Alan Coon  <alanc...@apple.com>
 
         Cherry-pick r286994. rdar://problem/86445989

Modified: branches/safari-613.1.12.1-branch/Source/WTF/wtf/FileSystem.cpp (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WTF/wtf/FileSystem.cpp	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WTF/wtf/FileSystem.cpp	2022-01-05 19:19:31 UTC (rev 287639)
@@ -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: branches/safari-613.1.12.1-branch/Source/WTF/wtf/FileSystem.h (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WTF/wtf/FileSystem.h	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WTF/wtf/FileSystem.h	2022-01-05 19:19:31 UTC (rev 287639)
@@ -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: branches/safari-613.1.12.1-branch/Source/WTF/wtf/cocoa/FileSystemCocoa.mm (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WTF/wtf/cocoa/FileSystemCocoa.mm	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WTF/wtf/cocoa/FileSystemCocoa.mm	2022-01-05 19:19:31 UTC (rev 287639)
@@ -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: branches/safari-613.1.12.1-branch/Source/WTF/wtf/mac/FileSystemMac.mm (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WTF/wtf/mac/FileSystemMac.mm	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WTF/wtf/mac/FileSystemMac.mm	2022-01-05 19:19:31 UTC (rev 287639)
@@ -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: branches/safari-613.1.12.1-branch/Source/WebKit/ChangeLog (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WebKit/ChangeLog	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WebKit/ChangeLog	2022-01-05 19:19:31 UTC (rev 287639)
@@ -1,3 +1,64 @@
+2022-01-05  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r287377. rdar://problem/86829012
+
+    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):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-12-22  Sihui Liu  <sihui_...@apple.com>
+
+            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:
+
 2022-01-04  Alan Coon  <alanc...@apple.com>
 
         Cherry-pick r287413. rdar://problem/86808395

Modified: branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2022-01-05 19:19:31 UTC (rev 287639)
@@ -644,15 +644,4 @@
 #endif
 }
 
-#if PLATFORM(IOS_FAMILY)
-
-void WebsiteDataStore::excludeDirectoryFromBackup(const String& directory)
-{
-    NSURL *url = "" URLWithString:(NSString *)directory];
-    if ([[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:nullptr])
-        [[NSURL fileURLWithPath:(NSString *)directory isDirectory:YES] setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
 }
-
-#endif
-
-}

Modified: branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2022-01-05 19:19:31 UTC (rev 287639)
@@ -1903,12 +1903,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: branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2022-01-05 19:19:31 UTC (rev 287639)
@@ -371,10 +371,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: branches/safari-613.1.12.1-branch/Tools/ChangeLog (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Tools/ChangeLog	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Tools/ChangeLog	2022-01-05 19:19:31 UTC (rev 287639)
@@ -1,3 +1,55 @@
+2022-01-05  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r287377. rdar://problem/86829012
+
+    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):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-12-22  Sihui Liu  <sihui_...@apple.com>
+
+            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-13  Youenn Fablet  <you...@apple.com>
 
         Fix ServiceWorker downloads

Modified: branches/safari-613.1.12.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm (287638 => 287639)


--- branches/safari-613.1.12.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm	2022-01-05 19:19:25 UTC (rev 287638)
+++ branches/safari-613.1.12.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm	2022-01-05 19:19:31 UTC (rev 287639)
@@ -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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to