if we are downloading an app, actually listen for the error event (add better logs for #4832)

This commit is contained in:
Jonathan Lipps 2015-04-13 14:15:09 -07:00
Родитель 16b2ca0dfa
Коммит c1f1f1ac04
2 изменённых файлов: 15 добавлений и 6 удалений

Просмотреть файл

@ -116,7 +116,8 @@ Device.prototype.configureDownloadedApp = function (cb) {
var ext = path.extname(appUrl.pathname);
if (ext === ".apk") {
try {
downloadFile(url.format(appUrl), ".apk", function (appPath) {
downloadFile(url.format(appUrl), ".apk", function (err, appPath) {
if (err) return cb(err);
this.tempFiles.push(appPath);
this.args.app = appPath;
cb();
@ -174,7 +175,8 @@ Device.prototype.unzipApp = function (zipPath, cb) {
};
Device.prototype.downloadAndUnzipApp = function (appUrl, cb) {
downloadFile(appUrl, ".zip", function (zipPath) {
downloadFile(appUrl, ".zip", function (err, zipPath) {
if (err) return cb(err);
this.unzipApp(zipPath, cb);
}.bind(this));
};

Просмотреть файл

@ -18,13 +18,20 @@ var logger = require('./server/logger.js').get('appium')
exports.downloadFile = function (fileUrl, suffix, cb) {
// We will be downloading the files to a directory, so make sure it's there
// This step is not required if you have manually created the directory
cb = _.once(cb);
tempDir.open({prefix: 'appium-app', suffix: suffix}).nodeify(function (err, info) {
fs.close(info.fd);
var file = fs.createWriteStream(info.path);
request(fileUrl).pipe(file).on('close', function () {
logger.debug(fileUrl + ' downloaded to ' + info.path);
cb(info.path);
});
request(fileUrl)
.on('error', function (err) {
logger.error("Problem downloading file: " + err.message);
cb(err);
})
.pipe(file)
.on('close', function () {
logger.debug(fileUrl + ' downloaded to ' + info.path);
cb(null, info.path);
});
});
};