Skip to content

Commit

Permalink
make sure that if we delete a built-in app, we look in /tmp to try an…
Browse files Browse the repository at this point in the history
…d launch it if it ends up being not put back yet
  • Loading branch information
jlipps committed Dec 20, 2013
1 parent 20e1580 commit 4d15974
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,36 @@ exports.unzipApp = function(zipPath, appExt, cb) {

exports.checkBuiltInApp = function(appName, version, cb) {
logger.info("Looking for built in app " + appName);
var newAppDir = path.resolve(exports.getTempPath(),
'Appium-' + appName + '.app');
var checkApp = function(s, appPath, cb) {
if (!s.isDirectory()) {
cb(new Error("App package was not a directory"), appPath);
return false;
}
return true;
};
exports.getBuiltInAppDir(version, function(err, appDir) {
if (err) return cb(err);
var appPath = path.resolve(appDir, appName + ".app");
fs.stat(appPath, function(err, s) {
if (err) return cb(err);
if (!s.isDirectory()) {
return cb(new Error("App package was not a directory"), appPath);
if (err && err.message.indexOf("ENOENT") !== -1) {
fs.stat(newAppDir, function(err, s) {
if (err) return cb(err);
if (checkApp(s, appPath, cb)) {
logger.info("Couldn't find original app, but found the temp " +
"Appium one so using that");
cb(null, newAppDir, appPath);
}
});
return;
} else if (err) {
return cb(err);
}
if (checkApp(s, appPath, cb)) {
logger.info("Got app, trying to copy " + appPath + " to tmp dir");
exports.moveBuiltInApp(appPath, appName, newAppDir, cb);
}
logger.info("Got app, trying to copy " + appPath + " to tmp dir");
exports.moveBuiltInApp(appPath, appName, cb);
});
});
};
Expand Down Expand Up @@ -173,8 +193,7 @@ exports.getBuiltInAppDir = function(version, cb) {
});
};

exports.moveBuiltInApp = function(appPath, appName, cb) {
var newAppDir = path.resolve(exports.getTempPath(), 'Appium-' + appName + '.app');
exports.moveBuiltInApp = function(appPath, appName, newAppDir, cb) {
ncp(appPath, newAppDir, function(err) {
if (err) return cb(err);
logger.info("Copied " + appName + " to " + newAppDir);
Expand Down

0 comments on commit 4d15974

Please sign in to comment.