mirror of
https://github.com/appium/appium.git
synced 2026-01-26 12:18:51 -06:00
extracted tempdir to appium-support
This commit is contained in:
@@ -7,14 +7,14 @@ var logger = require('./server/logger.js').get('appium')
|
||||
, path = require('path')
|
||||
, exec = require('child_process').exec
|
||||
, osType = require('os').type()
|
||||
, tempdir = require('./tempdir')
|
||||
, tempDir = require('appium-support').tempDir
|
||||
, AdmZip = require('adm-zip');
|
||||
|
||||
|
||||
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
|
||||
tempdir.open({prefix: 'appium-app', suffix: suffix}, function (err, info) {
|
||||
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 () {
|
||||
@@ -28,7 +28,7 @@ exports.copyLocalZip = function (localZipPath, cb) {
|
||||
logger.debug("Copying local zip to tmp dir");
|
||||
fs.stat(localZipPath, function (err) {
|
||||
if (err) return cb(err);
|
||||
tempdir.open({prefix: 'appium-app', suffix: '.zip'}, function (err, info) {
|
||||
tempDir.open({prefix: 'appium-app', suffix: '.zip'}).nodeify(function (err, info) {
|
||||
var infile = fs.createReadStream(localZipPath);
|
||||
var outfile = fs.createWriteStream(info.path);
|
||||
infile.pipe(outfile).on('close', function () {
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/* This library is originated from temp.js at http://github.com/bruce/node-temp */
|
||||
"use strict";
|
||||
|
||||
var fs = require('fs')
|
||||
, os = require('os')
|
||||
, path = require('path')
|
||||
, cnst = require('constants');
|
||||
|
||||
var RDWR_EXCL = cnst.O_CREAT | cnst.O_TRUNC | cnst.O_RDWR | cnst.O_EXCL;
|
||||
|
||||
var tempDir = function () {
|
||||
var now = new Date();
|
||||
var filePath = path.join(os.tmpDir(),
|
||||
[now.getYear(), now.getMonth(), now.getDate(),
|
||||
'-',
|
||||
process.pid,
|
||||
'-',
|
||||
(Math.random() * 0x100000000 + 1).toString(36)].join(''));
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.mkdirSync(filePath);
|
||||
}
|
||||
return filePath;
|
||||
};
|
||||
|
||||
var generateName = function (rawAffixes, defaultPrefix) {
|
||||
var affixes = parseAffixes(rawAffixes, defaultPrefix);
|
||||
var name = [affixes.prefix, affixes.suffix].join('');
|
||||
return path.join(tempDir(), name);
|
||||
};
|
||||
|
||||
|
||||
var open = function (affixes, callback) {
|
||||
var filePath = generateName(affixes, 'f-');
|
||||
fs.open(filePath, RDWR_EXCL, 384, function (err, fd) {
|
||||
if (callback)
|
||||
callback(err, {path: filePath, fd: fd});
|
||||
});
|
||||
};
|
||||
|
||||
var parseAffixes = function (rawAffixes, defaultPrefix) {
|
||||
var affixes = {prefix: null, suffix: null};
|
||||
if (rawAffixes) {
|
||||
switch (typeof(rawAffixes)) {
|
||||
case 'string':
|
||||
affixes.prefix = rawAffixes;
|
||||
break;
|
||||
case 'object':
|
||||
affixes = rawAffixes;
|
||||
break;
|
||||
default:
|
||||
throw ("Unknown affix declaration: " + affixes);
|
||||
}
|
||||
} else {
|
||||
affixes.prefix = defaultPrefix;
|
||||
}
|
||||
return affixes;
|
||||
};
|
||||
|
||||
exports.open = open;
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"appium-adb": "=1.6.0",
|
||||
"appium-atoms": "=0.0.5",
|
||||
"appium-instruments": "=1.5.3",
|
||||
"appium-support": "=0.0.2",
|
||||
"appium-uiauto": "=1.10.2",
|
||||
"argparse": "~0.1.15",
|
||||
"async": "~0.9.0",
|
||||
|
||||
@@ -4,7 +4,7 @@ var initSession = require('../../helpers/session').initSession
|
||||
, getTitle = require('../../helpers/title').getTitle
|
||||
, _ = require('underscore')
|
||||
, getAppPath = require('../../helpers/app').getAppPath
|
||||
, tempdir = require('../../../lib/tempdir')
|
||||
, tempDir = require('appium-support').tempDir
|
||||
, ncp = require('ncp');
|
||||
|
||||
require('../../helpers/setup-chai.js');
|
||||
@@ -15,7 +15,7 @@ module.exports.spacesTest = function (desired) {
|
||||
var oldAppPath = getAppPath('ApiDemos');
|
||||
var newAppPath = '/tmp/App With Spaces.apk';
|
||||
before(function (done) {
|
||||
tempdir.open({prefix: 'app with spaces', suffix: '.apk'}, function (err, info) {
|
||||
tempDir.open({prefix: 'app with spaces', suffix: '.apk'}).nodeify(function (err, info) {
|
||||
if (err) return done(err);
|
||||
console.log("Copying '" + oldAppPath + "' to '" + info.path + "'");
|
||||
ncp(oldAppPath, info.path, function (err) {
|
||||
|
||||
Reference in New Issue
Block a user