⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287639 in webkit


Ignore:
Timestamp:
Jan 5, 2022, 11:19:31 AM (5 years ago)
Author:
Russell Epstein
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

Location:
branches/safari-613.1.12.1-branch
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-613.1.12.1-branch/Source/WTF/ChangeLog

    r287165 r287639  
     12022-01-05  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r287377. rdar://problem/86829012
     4
     5    WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     6    https://bugs.webkit.org/show_bug.cgi?id=234404
     7   
     8    Reviewed by Youenn Fablet.
     9   
     10    Source/WebKit:
     11   
     12    createDirectoryAtURL returning false means directory cannot be created, but the cause can be that directory
     13    already exists; so we should set exclude attribute on the directory no matter createDirectoryAtURL returns true
     14    or false. Also, we can use existing FileSystem functions.
     15   
     16    API test: WKWebView.LocalStorageDirectoryExcludedFromBackup
     17   
     18    * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     19    (WebKit::WebsiteDataStore::excludeDirectoryFromBackup): Deleted.
     20    * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     21    (WebKit::WebsiteDataStore::parameters):
     22    * UIProcess/WebsiteData/WebsiteDataStore.h:
     23   
     24    Source/WTF:
     25   
     26    * wtf/FileSystem.cpp:
     27    (WTF::FileSystemImpl::excludeFromBackup):
     28    (WTF::FileSystemImpl::canExcludeFromBackup): Deleted.
     29    * wtf/FileSystem.h:
     30    * wtf/cocoa/FileSystemCocoa.mm:
     31    (WTF::FileSystemImpl::excludeFromBackup):
     32    * wtf/mac/FileSystemMac.mm:
     33    (WTF::FileSystem::canExcludeFromBackup): Deleted.
     34    (WTF::FileSystem::excludeFromBackup): Deleted.
     35   
     36    Tools:
     37   
     38    * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
     39    (TEST):
     40   
     41    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     42
     43    2021-12-22  Sihui Liu  <sihui_liu@apple.com>
     44
     45            WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     46            https://bugs.webkit.org/show_bug.cgi?id=234404
     47
     48            Reviewed by Youenn Fablet.
     49
     50            * wtf/FileSystem.cpp:
     51            (WTF::FileSystemImpl::excludeFromBackup):
     52            (WTF::FileSystemImpl::canExcludeFromBackup): Deleted.
     53            * wtf/FileSystem.h:
     54            * wtf/cocoa/FileSystemCocoa.mm:
     55            (WTF::FileSystemImpl::excludeFromBackup):
     56            * wtf/mac/FileSystemMac.mm:
     57            (WTF::FileSystem::canExcludeFromBackup): Deleted.
     58            (WTF::FileSystem::excludeFromBackup): Deleted.
     59
    1602021-12-16  Alan Coon  <alancoon@apple.com>
    261
  • branches/safari-613.1.12.1-branch/Source/WTF/wtf/FileSystem.cpp

    r286883 r287639  
    306306}
    307307
    308 bool canExcludeFromBackup()
    309 {
    310     return false;
    311 }
    312 
    313 bool excludeFromBackup(const String&)
    314 {
    315     return false;
    316 }
    317 
    318308#endif
    319309
    … …  
    427417
    428418#if !PLATFORM(COCOA)
     419
    429420String createTemporaryZipArchive(const String&)
    430421{
    431422    return { };
    432423}
     424
     425bool excludeFromBackup(const String&)
     426{
     427    return false;
     428}
     429
    433430#endif
    434431
  • branches/safari-613.1.12.1-branch/Source/WTF/wtf/FileSystem.h

    r286883 r287639  
    135135
    136136WTF_EXPORT_PRIVATE void setMetadataURL(const String& path, const String& urlString, const String& referrer = { });
    137 
    138 bool canExcludeFromBackup(); // Returns true if any file can ever be excluded from backup.
    139 bool excludeFromBackup(const String&); // Returns true if successful.
     137WTF_EXPORT_PRIVATE bool excludeFromBackup(const String&); // Returns true if successful.
    140138
    141139WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path); // Returns file names, not full paths.
  • branches/safari-613.1.12.1-branch/Source/WTF/wtf/cocoa/FileSystemCocoa.mm

    r278431 r287639  
    223223#endif
    224224
     225bool excludeFromBackup(const String& path)
     226{
     227    NSError *error;
     228    if (![[NSURL fileURLWithPath:(NSString *)path isDirectory:YES] setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:&error]) {
     229        LOG_ERROR("Cannot exclude path '%s' from backup with error '%@'", path.utf8().data(), error.localizedDescription);
     230        return false;
     231    }
     232
     233    return true;
     234}
     235
    225236} // namespace FileSystemImpl
    226237} // namespace WTF
  • branches/safari-613.1.12.1-branch/Source/WTF/wtf/mac/FileSystemMac.mm

    r285588 r287639  
    5858}
    5959
    60 bool FileSystem::canExcludeFromBackup()
    61 {
    62     return true;
    63 }
    64 
    65 bool FileSystem::excludeFromBackup(const String& path)
    66 {
    67     // It is critical to pass FALSE for excludeByPath because excluding by path requires root privileges.
    68     CSBackupSetItemExcluded(FileSystem::pathAsURL(path).get(), TRUE, FALSE);
    69     return true;
    70 }
    71 
    7260} // namespace WTF
    7361
  • branches/safari-613.1.12.1-branch/Source/WebKit/ChangeLog

    r287594 r287639  
     12022-01-05  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r287377. rdar://problem/86829012
     4
     5    WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     6    https://bugs.webkit.org/show_bug.cgi?id=234404
     7   
     8    Reviewed by Youenn Fablet.
     9   
     10    Source/WebKit:
     11   
     12    createDirectoryAtURL returning false means directory cannot be created, but the cause can be that directory
     13    already exists; so we should set exclude attribute on the directory no matter createDirectoryAtURL returns true
     14    or false. Also, we can use existing FileSystem functions.
     15   
     16    API test: WKWebView.LocalStorageDirectoryExcludedFromBackup
     17   
     18    * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     19    (WebKit::WebsiteDataStore::excludeDirectoryFromBackup): Deleted.
     20    * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     21    (WebKit::WebsiteDataStore::parameters):
     22    * UIProcess/WebsiteData/WebsiteDataStore.h:
     23   
     24    Source/WTF:
     25   
     26    * wtf/FileSystem.cpp:
     27    (WTF::FileSystemImpl::excludeFromBackup):
     28    (WTF::FileSystemImpl::canExcludeFromBackup): Deleted.
     29    * wtf/FileSystem.h:
     30    * wtf/cocoa/FileSystemCocoa.mm:
     31    (WTF::FileSystemImpl::excludeFromBackup):
     32    * wtf/mac/FileSystemMac.mm:
     33    (WTF::FileSystem::canExcludeFromBackup): Deleted.
     34    (WTF::FileSystem::excludeFromBackup): Deleted.
     35   
     36    Tools:
     37   
     38    * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
     39    (TEST):
     40   
     41    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     42
     43    2021-12-22  Sihui Liu  <sihui_liu@apple.com>
     44
     45            WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     46            https://bugs.webkit.org/show_bug.cgi?id=234404
     47
     48            Reviewed by Youenn Fablet.
     49
     50            createDirectoryAtURL returning false means directory cannot be created, but the cause can be that directory
     51            already exists; so we should set exclude attribute on the directory no matter createDirectoryAtURL returns true
     52            or false. Also, we can use existing FileSystem functions.
     53
     54            API test: WKWebView.LocalStorageDirectoryExcludedFromBackup
     55
     56            * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     57            (WebKit::WebsiteDataStore::excludeDirectoryFromBackup): Deleted.
     58            * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     59            (WebKit::WebsiteDataStore::parameters):
     60            * UIProcess/WebsiteData/WebsiteDataStore.h:
     61
    1622022-01-04  Alan Coon  <alancoon@apple.com>
    263
  • branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r286936 r287639  
    645645}
    646646
    647 #if PLATFORM(IOS_FAMILY)
    648 
    649 void WebsiteDataStore::excludeDirectoryFromBackup(const String& directory)
    650 {
    651     NSURL *url = [NSURL URLWithString:(NSString *)directory];
    652     if ([[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:nullptr])
    653         [[NSURL fileURLWithPath:(NSString *)directory isDirectory:YES] setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
    654 }
    655 
    656 #endif
    657 
    658 }
     647}
  • branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r286936 r287639  
    19041904    if (!localStorageDirectory.isEmpty()) {
    19051905        parameters.localStorageDirectory = localStorageDirectory;
    1906 #if PLATFORM(IOS_FAMILY)
    1907         excludeDirectoryFromBackup(localStorageDirectory);
    1908 #endif
    19091906        // FIXME: SandboxExtension::createHandleForReadWriteDirectory resolves the directory, but that has already been done. Remove this duplicate work.
    19101907        if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(localStorageDirectory))
    19111908            parameters.localStorageDirectoryExtensionHandle = WTFMove(*handle);
     1909#if PLATFORM(IOS_FAMILY)
     1910        FileSystem::makeAllDirectories(localStorageDirectory);
     1911        FileSystem::excludeFromBackup(localStorageDirectory);
     1912#endif
    19121913    }
    19131914
  • branches/safari-613.1.12.1-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r286936 r287639  
    372372    void countNonDefaultSessionSets(CompletionHandler<void(size_t)>&&);
    373373
    374 #if PLATFORM(IOS_FAMILY)
    375     void excludeDirectoryFromBackup(const String& directory);
    376 #endif
    377 
    378374private:
    379375    enum class ForceReinitialization : bool { No, Yes };
  • branches/safari-613.1.12.1-branch/Tools/ChangeLog

    r287061 r287639  
     12022-01-05  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r287377. rdar://problem/86829012
     4
     5    WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     6    https://bugs.webkit.org/show_bug.cgi?id=234404
     7   
     8    Reviewed by Youenn Fablet.
     9   
     10    Source/WebKit:
     11   
     12    createDirectoryAtURL returning false means directory cannot be created, but the cause can be that directory
     13    already exists; so we should set exclude attribute on the directory no matter createDirectoryAtURL returns true
     14    or false. Also, we can use existing FileSystem functions.
     15   
     16    API test: WKWebView.LocalStorageDirectoryExcludedFromBackup
     17   
     18    * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     19    (WebKit::WebsiteDataStore::excludeDirectoryFromBackup): Deleted.
     20    * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     21    (WebKit::WebsiteDataStore::parameters):
     22    * UIProcess/WebsiteData/WebsiteDataStore.h:
     23   
     24    Source/WTF:
     25   
     26    * wtf/FileSystem.cpp:
     27    (WTF::FileSystemImpl::excludeFromBackup):
     28    (WTF::FileSystemImpl::canExcludeFromBackup): Deleted.
     29    * wtf/FileSystem.h:
     30    * wtf/cocoa/FileSystemCocoa.mm:
     31    (WTF::FileSystemImpl::excludeFromBackup):
     32    * wtf/mac/FileSystemMac.mm:
     33    (WTF::FileSystem::canExcludeFromBackup): Deleted.
     34    (WTF::FileSystem::excludeFromBackup): Deleted.
     35   
     36    Tools:
     37   
     38    * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
     39    (TEST):
     40   
     41    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     42
     43    2021-12-22  Sihui Liu  <sihui_liu@apple.com>
     44
     45            WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     46            https://bugs.webkit.org/show_bug.cgi?id=234404
     47
     48            Reviewed by Youenn Fablet.
     49
     50            * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
     51            (TEST):
     52
    1532021-12-13  Youenn Fablet  <youenn@apple.com>
    254
  • branches/safari-613.1.12.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm

    r285547 r287639  
    4040#import <WebKit/_WKProcessPoolConfiguration.h>
    4141#import <WebKit/_WKUserStyleSheet.h>
     42#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
    4243#import <wtf/RetainPtr.h>
    4344#import <wtf/text/WTFString.h>
    … …  
    453454    runTest(false);
    454455}
     456
     457#if PLATFORM(IOS_FAMILY)
     458
     459TEST(WKWebView, LocalStorageDirectoryExcludedFromBackup)
     460{
     461    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     462    RetainPtr<NSURL> url = [[[configuration websiteDataStore] _configuration] _webStorageDirectory];
     463    // Create a directory and make it not excluded.
     464    [[NSFileManager defaultManager] createDirectoryAtURL:url.get() withIntermediateDirectories:YES attributes:nil error:nullptr];
     465    [url.get() setResourceValue:@NO forKey:NSURLIsExcludedFromBackupKey error:nil];
     466    NSNumber *isDirectoryExcluded = nil;
     467    EXPECT_TRUE([url.get() getResourceValue:&isDirectoryExcluded forKey:NSURLIsExcludedFromBackupKey error:nil]);
     468    EXPECT_FALSE(isDirectoryExcluded.boolValue);
     469
     470    auto delegate = adoptNS([[LocalStorageNavigationDelegate alloc] init]);
     471    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     472    [webView setNavigationDelegate:delegate.get()];
     473    didFinishNavigationBoolean = false;
     474    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     475    [webView loadRequest:request];
     476    TestWebKitAPI::Util::run(&didFinishNavigationBoolean);
     477
     478    bool finishedRunningScript = false;
     479    [webView evaluateJavaScript:@"localStorage.getItem('key');" completionHandler: [&] (id result, NSError *) {
     480        finishedRunningScript = true;
     481    }];
     482    TestWebKitAPI::Util::run(&finishedRunningScript);
     483
     484    // Create new url that has updated value.
     485    url = [[[configuration websiteDataStore] _configuration] _webStorageDirectory];
     486    EXPECT_TRUE([url.get() getResourceValue:&isDirectoryExcluded forKey:NSURLIsExcludedFromBackupKey error:nil]);
     487    EXPECT_TRUE(isDirectoryExcluded.boolValue);
     488}
     489
     490#endif
Note: See TracChangeset for help on using the changeset viewer.