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

Changeset 287377 in webkit


Ignore:
Timestamp:
Dec 22, 2021, 3:55:10 PM (5 years ago)
Author:
sihui_liu@apple.com
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):

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r287372 r287377  
     12021-12-22  Sihui Liu  <sihui_liu@apple.com>
     2
     3        WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     4        https://bugs.webkit.org/show_bug.cgi?id=234404
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * wtf/FileSystem.cpp:
     9        (WTF::FileSystemImpl::excludeFromBackup):
     10        (WTF::FileSystemImpl::canExcludeFromBackup): Deleted.
     11        * wtf/FileSystem.h:
     12        * wtf/cocoa/FileSystemCocoa.mm:
     13        (WTF::FileSystemImpl::excludeFromBackup):
     14        * wtf/mac/FileSystemMac.mm:
     15        (WTF::FileSystem::canExcludeFromBackup): Deleted.
     16        (WTF::FileSystem::excludeFromBackup): Deleted.
     17
    1182021-12-22  Commit Queue  <commit-queue@webkit.org>
    219
  • trunk/Source/WTF/wtf/FileSystem.cpp

    r287080 r287377  
    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
  • trunk/Source/WTF/wtf/FileSystem.h

    r286883 r287377  
    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.
  • trunk/Source/WTF/wtf/cocoa/FileSystemCocoa.mm

    r278431 r287377  
    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
  • trunk/Source/WTF/wtf/mac/FileSystemMac.mm

    r285588 r287377  
    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
  • trunk/Source/WebKit/ChangeLog

    r287374 r287377  
     12021-12-22  Sihui Liu  <sihui_liu@apple.com>
     2
     3        WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     4        https://bugs.webkit.org/show_bug.cgi?id=234404
     5
     6        Reviewed by Youenn Fablet.
     7
     8        createDirectoryAtURL returning false means directory cannot be created, but the cause can be that directory
     9        already exists; so we should set exclude attribute on the directory no matter createDirectoryAtURL returns true
     10        or false. Also, we can use existing FileSystem functions.
     11
     12        API test: WKWebView.LocalStorageDirectoryExcludedFromBackup
     13
     14        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     15        (WebKit::WebsiteDataStore::excludeDirectoryFromBackup): Deleted.
     16        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     17        (WebKit::WebsiteDataStore::parameters):
     18        * UIProcess/WebsiteData/WebsiteDataStore.h:
     19
    1202021-12-22  Alex Christensen  <achristensen@webkit.org>
    221
  • trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r287344 r287377  
    641641}
    642642
    643 #if PLATFORM(IOS_FAMILY)
    644 
    645 void WebsiteDataStore::excludeDirectoryFromBackup(const String& directory)
    646 {
    647     NSURL *url = [NSURL fileURLWithPath:(NSString *)directory isDirectory:YES];
    648     if ([[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:nullptr])
    649         [url setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
    650 }
    651 
    652 #endif
    653 
    654 }
     643}
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r287371 r287377  
    19151915    if (!localStorageDirectory.isEmpty()) {
    19161916        parameters.localStorageDirectory = localStorageDirectory;
    1917 #if PLATFORM(IOS_FAMILY)
    1918         excludeDirectoryFromBackup(localStorageDirectory);
    1919 #endif
    19201917        // FIXME: SandboxExtension::createHandleForReadWriteDirectory resolves the directory, but that has already been done. Remove this duplicate work.
    19211918        if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(localStorageDirectory))
    19221919            parameters.localStorageDirectoryExtensionHandle = WTFMove(*handle);
     1920#if PLATFORM(IOS_FAMILY)
     1921        FileSystem::makeAllDirectories(localStorageDirectory);
     1922        FileSystem::excludeFromBackup(localStorageDirectory);
     1923#endif
    19231924    }
    19241925
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r287371 r287377  
    373373    void countNonDefaultSessionSets(CompletionHandler<void(size_t)>&&);
    374374
    375 #if PLATFORM(IOS_FAMILY)
    376     void excludeDirectoryFromBackup(const String& directory);
    377 #endif
    378 
    379375private:
    380376    enum class ForceReinitialization : bool { No, Yes };
  • trunk/Tools/ChangeLog

    r287374 r287377  
     12021-12-22  Sihui Liu  <sihui_liu@apple.com>
     2
     3        WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
     4        https://bugs.webkit.org/show_bug.cgi?id=234404
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
     9        (TEST):
     10
    1112021-12-22  Alex Christensen  <achristensen@webkit.org>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm

    r285547 r287377  
    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.