Skip to content

Commit

Permalink
getiOSSDKVersion only returns major version, but we need minor versio…
Browse files Browse the repository at this point in the history
…ns for clearing out safari. use glob instead
  • Loading branch information
jlipps committed Dec 20, 2013
1 parent 20c368f commit 93f6306
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,51 +213,58 @@ exports.moveBuiltInApp = function(appPath, appName, newAppDir, cb) {

exports.cleanSafari = function(safariVer, cb) {
var baseDir = "Library/Application Support/iPhone Simulator/" +
safariVer + "/Library/";
safariVer + "*/Library/";
exports.getUser(function(err, user) {
if (err) {
logger.error(err);
cb(err);
} else {
var baseSupportDir = path.resolve("/Users", user, baseDir);
fs.stat(baseSupportDir, function(err) {
if (err) {
logger.info(err.message);
var p = process.env.HOME + '/' + baseDir;
if(!fs.existsSync(p)) {
return cb(new Error("Could not find support directory for mobile safari, does " +
"it exist at " + baseDir + " or " + p + "?"));
} else {
baseSupportDir = p;
}
var baseSupportDirs = path.resolve("/Users", user, baseDir);
glob(baseSupportDirs, function(err, pathList) {
if (err) return cb(err);
if (pathList.length === 0) {
logger.info("Couldn't find Safari support directories in order " +
"to clear out old data");
return cb();
}
var toDeletes = [
'Caches/Snapshots/com.apple.mobilesafari'
, 'Caches/com.apple.mobilesafari/Cache.db*'
, 'Caches/com.apple.WebAppCache/*.db'
, 'Safari/*.plist'
, 'WebKit/LocalStorage/*.*'
, 'Library/WebKit/GeolocationSites.plist'
, 'Cookies/*.binarycookies'
];
var deletes = 0;
var pathsFinished = 0;
var errToRet = null;
var finish = function(err) {
deletes++;
if (err) {
errToRet = err;
}
if (deletes === toDeletes.length) {
cb(errToRet);
var finishAll = function(err) {
if (err) errToRet = err;
pathsFinished++;
if (pathsFinished === pathList.length) {
cb(err);
}
};
_.each(toDeletes, function(del) {
var toDelete = path.resolve(baseSupportDir, del);
toDelete = toDelete.replace(/ /g, "\\ ");
logger.info("Deleting " + toDelete);
var cmd = "rm -rf " + toDelete;
exec(cmd, function(err) {
finish(err);
_.each(pathList, function(baseSupportDir) {
var toDeletes = [
'Caches/Snapshots/com.apple.mobilesafari'
, 'Caches/com.apple.mobilesafari/Cache.db*'
, 'Caches/com.apple.WebAppCache/*.db'
, 'Safari/*.plist'
, 'WebKit/LocalStorage/*.*'
, 'Library/WebKit/GeolocationSites.plist'
, 'Cookies/*.binarycookies'
];
var deletes = 0;
var errToRet = null;
var finishOne = function(err) {
deletes++;
if (err) {
errToRet = err;
}
if (deletes === toDeletes.length) {
finishAll(errToRet);
}
};
_.each(toDeletes, function(del) {
var toDelete = path.resolve(baseSupportDir, del);
toDelete = toDelete.replace(/ /g, "\\ ");
logger.info("Deleting " + toDelete);
var cmd = "rm -rf " + toDelete;
exec(cmd, function(err) {
finishOne(err);
});
});
});
});
Expand Down

0 comments on commit 93f6306

Please sign in to comment.