Title: [185525] trunk/Source/WebCore
Revision
185525
Author
[email protected]
Date
2015-06-12 17:18:29 -0700 (Fri, 12 Jun 2015)

Log Message

deleteEmptyDirectory should delete .DS_Store files on OS X
https://bugs.webkit.org/show_bug.cgi?id=145944

Reviewed by Dan Bernstein.

deleteEmptyDirectory is often used when clearing website data, so we should
take extra care to delete empty directories so the user won't think that clearing
website data didn't do anything because it would leave directories with .DS_Store
files behind.

* platform/mac/FileSystemMac.mm:
(WebCore::deleteEmptyDirectory):
* platform/posix/FileSystemPOSIX.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (185524 => 185525)


--- trunk/Source/WebCore/ChangeLog	2015-06-12 23:40:08 UTC (rev 185524)
+++ trunk/Source/WebCore/ChangeLog	2015-06-13 00:18:29 UTC (rev 185525)
@@ -1,3 +1,19 @@
+2015-06-12  Anders Carlsson  <[email protected]>
+
+        deleteEmptyDirectory should delete .DS_Store files on OS X
+        https://bugs.webkit.org/show_bug.cgi?id=145944
+
+        Reviewed by Dan Bernstein.
+
+        deleteEmptyDirectory is often used when clearing website data, so we should
+        take extra care to delete empty directories so the user won't think that clearing
+        website data didn't do anything because it would leave directories with .DS_Store 
+        files behind.
+
+        * platform/mac/FileSystemMac.mm:
+        (WebCore::deleteEmptyDirectory):
+        * platform/posix/FileSystemPOSIX.cpp:
+
 2015-06-12  Manuel Rego Casasnovas  <[email protected]>
 
         [CSS Grid Layout] Fix grid-template-areas parsing to avoid spaces

Modified: trunk/Source/WebCore/platform/mac/FileSystemMac.mm (185524 => 185525)


--- trunk/Source/WebCore/platform/mac/FileSystemMac.mm	2015-06-12 23:40:08 UTC (rev 185524)
+++ trunk/Source/WebCore/platform/mac/FileSystemMac.mm	2015-06-13 00:18:29 UTC (rev 185525)
@@ -95,7 +95,20 @@
 }
 
 #if !PLATFORM(IOS)
+bool deleteEmptyDirectory(const String& path)
+{
+    auto fileManager = adoptNS([[NSFileManager alloc] init]);
 
+    if (NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:path error:nullptr]) {
+        // Explicitly look for and delete .DS_Store files.
+        if (directoryContents.count == 1 && [directoryContents.firstObject isEqualToString:@".DS_Store"])
+            [fileManager removeItemAtPath:[path stringByAppendingPathComponent:directoryContents.firstObject] error:nullptr];
+    }
+
+    // rmdir(...) returns 0 on successful deletion of the path and non-zero in any other case (including invalid permissions or non-existent file)
+    return !rmdir(fileSystemRepresentation(path).data());
+}
+
 void setMetadataURL(String& URLString, const String& referrer, const String& path)
 {
     NSURL *URL = "" nil);

Modified: trunk/Source/WebCore/platform/posix/FileSystemPOSIX.cpp (185524 => 185525)


--- trunk/Source/WebCore/platform/posix/FileSystemPOSIX.cpp	2015-06-12 23:40:08 UTC (rev 185524)
+++ trunk/Source/WebCore/platform/posix/FileSystemPOSIX.cpp	2015-06-13 00:18:29 UTC (rev 185525)
@@ -156,6 +156,7 @@
 }
 #endif
 
+#if !PLATFORM(MAC)
 bool deleteEmptyDirectory(const String& path)
 {
     CString fsRep = fileSystemRepresentation(path);
@@ -166,6 +167,7 @@
     // rmdir(...) returns 0 on successful deletion of the path and non-zero in any other case (including invalid permissions or non-existent file)
     return !rmdir(fsRep.data());
 }
+#endif
 
 bool getFileSize(const String& path, long long& result)
 {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to