Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: tools/testing/dart/browser_controller.dart

Issue 17450017: Also remove Library/Safari from users home dir if --clear_safari_cache is set (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/browser_controller.dart
===================================================================
--- tools/testing/dart/browser_controller.dart (revision 24231)
+++ tools/testing/dart/browser_controller.dart (working copy)
@@ -183,6 +183,15 @@
*/
const String versionFile = "/Applications/Safari.app/Contents/version.plist";
+ /**
+ * Directories where safari stores state. We delete these if the deleteCache
+ * is set
+ */
+ static const List<String> CACHE_DIRECTORIES =
+ const ["Library/Caches/com.apple.Safari",
+ "Library/Safari"];
+
+
Future<bool> allowPopUps() {
var command = "defaults";
var args = ["write", "com.apple.safari",
@@ -198,17 +207,32 @@
});
}
+ Future<bool> deleteIfExists(Iterator<String> paths) {
+ if (!paths.moveNext()) return new Future.immediate(true);
+ Directory directory = new Directory(paths.current);
+ return directory.exists().then((exists) {
+ if (exists) {
+ _logEvent("Deleting ${paths.current}");
+ return directory.delete(recursive: true)
+ .then((_) => deleteIfExists(paths))
+ .catchError((error) {
+ _logEvent("Failure trying to delete ${paths.current}: $error");
+ return false;
+ });
+ } else {
+ _logEvent("${paths.current} is not present");
+ return deleteIfExists(paths);
+ }
+ });
+ }
+
// Clears the cache if the static deleteCache flag is set.
// Returns false if the command to actually clear the cache did not complete.
Future<bool> clearCache() {
if (!deleteCache) return new Future.immediate(true);
var home = Platform.environment['HOME'];
- var cache = "$home/Library/Caches/com.apple.Safari";
- _logEvent("Clearing safari cache: $cache}");
- return new Directory(cache).delete(recursive: true)
- .then((_) => true)
- // This normally means that the directory was not there.
- .catchError((error) => true);
+ Iterator iterator = CACHE_DIRECTORIES.map((s) => "$home/$s").iterator;
+ return deleteIfExists(iterator);
}
Future<String> getVersion() {
@@ -256,9 +280,13 @@
_logEvent("Starting Safari browser on: $url");
return allowPopUps().then((success) {
if (!success) {
- return new Future.immediate(false);
+ return false;
}
- return clearCache().then((_) {
+ return clearCache().then((cleared) {
+ if (!cleared) {
+ _logEvent("Could not clear cache");
+ return false;
+ }
// Get the version and log that.
return getVersion().then((version) {
_logEvent("Got version: $version");
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698