Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
prefix: binarySpec,
suffix: '.zip'
});
log(`Opened temp file '${tempFile.path}'`);
// actually download the zipfile and write it with appropriate perms
log(`Downloading ${url}...`);
const body = await request.get({url, encoding: 'binary'});
log(`Writing binary content to ${tempFile.path}...`);
await fs.writeFile(tempFile.path, body, {encoding: 'binary'});
await fs.chmod(tempFile.path, 0o0644);
// extract downloaded zipfile to tempdir
const tempUnzipped = path.resolve(path.dirname(tempFile.path), binarySpec);
log(`Extracting ${tempFile.path} to ${tempUnzipped}`);
await mkdirp(tempUnzipped);
await zip.extractAllTo(tempFile.path, tempUnzipped);
let extractedBin = path.resolve(tempUnzipped, 'chromedriver');
if (platform === 'win') {
extractedBin += '.exe';
}
// make build dirs that will hold the chromedriver binary
log(`Creating ${path.resolve(CD_BASE_DIR, platform)}...`);
await mkdirp(path.resolve(CD_BASE_DIR, platform));
// copy the extracted binary to the correct build dir
const newBin = await getChromedriverBinaryPath(platform, arch);
log(`Copying unzipped binary, reading from ${extractedBin}...`);
const binContents = await fs.readFile(extractedBin, {encoding: 'binary'});
log(`Writing to ${newBin}...`);
await fs.writeFile(newBin, binContents, {encoding: 'binary', mode: 0o755});
async launchOnce () {
log.info('Launching instruments');
// prepare temp dir
await fs.rimraf(this.tmpDir);
await mkdirp(this.tmpDir);
await mkdirp(this.traceDir);
this.exitListener = null;
this.proc = await this.spawnInstruments();
this.proc.on('exit', (code, signal) => {
const msg = code !== null ? `code: ${code}` : `signal: ${signal}`;
log.debug(`Instruments exited with ${msg}`);
});
// set up the promise to handle launch
let launchResultPromise = new B((resolve, reject) => {
this.launchResultDeferred = {resolve, reject};
});
// There was a special case for ignoreStartupExit
// but it is not needed anymore, you may just listen for exit.
async getDB () {
if (this.db) {
return this.db;
}
// If the sim doesn't have a keychains directory, create one
let keychainsPath = path.resolve(this.sharedResourceDir, 'Library', 'Keychains');
if (!(await fs.exists(keychainsPath))) {
await mkdirp(keychainsPath);
}
// Open sqlite database
this.db = path.resolve(keychainsPath, 'TrustStore.sqlite3');
// If it doesn't have a tsettings table, create one
await execSQLiteQuery(this.db, `CREATE TABLE IF NOT EXISTS tsettings (sha1 BLOB NOT NULL DEFAULT '', subj BLOB NOT NULL DEFAULT '', tset BLOB, data BLOB, PRIMARY KEY(sha1));`);
try {
await execSQLiteQuery(this.db, 'CREATE INDEX isubj ON tsettings(subj);');
} catch (e) { }
return this.db;
}
async launchOnce () {
log.info('Launching instruments');
// prepare temp dir
await fs.rimraf(this.tmpDir);
await mkdirp(this.tmpDir);
await mkdirp(this.traceDir);
this.exitListener = null;
this.proc = await this.spawnInstruments();
this.proc.on('exit', (code, signal) => {
const msg = code !== null ? `code: ${code}` : `signal: ${signal}`;
log.debug(`Instruments exited with ${msg}`);
});
// set up the promise to handle launch
let launchResultPromise = new B((resolve, reject) => {
this.launchResultDeferred = {resolve, reject};
});
// There was a special case for ignoreStartupExit
// but it is not needed anymore, you may just listen for exit.
this.setExitListener(() => {
async function validateTmpDir (tmpDir) {
try {
await mkdirp(tmpDir);
} catch (e) {
throw new Error(`We could not ensure that the temp dir you specified ` +
`(${tmpDir}) exists. Please make sure it's writeable.`);
}
}
try {
await exec(this.binaries.zipalign, ['-c', '4', apk]);
log.debug(`${apk}' is already zip-aligned. Doing nothing`);
return false;
} catch (e) {
log.debug(`'${apk}' is not zip-aligned. Aligning`);
}
try {
await fs.access(apk, _fs.W_OK);
} catch (e) {
throw new Error(`The file at '${apk}' is not writeable. ` +
`Please grant write permissions to this file or to its parent folder '${path.dirname(apk)}' ` +
`for the Appium process, so it can zip-align the file`);
}
const alignedApk = await tempDir.path({prefix: 'appium', suffix: '.tmp'});
await mkdirp(path.dirname(alignedApk));
try {
await exec(this.binaries.zipalign, ['-f', '4', apk, alignedApk]);
await fs.mv(alignedApk, apk, { mkdirp: true });
return true;
} catch (e) {
if (await fs.exists(alignedApk)) {
await fs.unlink(alignedApk);
}
throw new Error(`zipAlignApk failed. Original error: ${e.message}. Stdout: '${e.stdout}'; Stderr: '${e.stderr}'`);
}
};
commands.pushFile = async function pushFile (remotePath, base64Data) {
logger.debug(`Pushing ${remotePath} to iOS simulator`);
if (this.isRealDevice()) {
logger.debug('Unsupported: cannot write files to physical device');
throw new errors.NotYetImplementedError();
}
let fullPath = await this.getSimFileFullPath(remotePath);
logger.debug(`Attempting to write ${fullPath}...`);
if (await fs.exists(fullPath)) {
logger.debug(`${fullPath} already exists, deleting...`);
await fs.unlink(fullPath);
}
await mkdirp(path.dirname(fullPath));
let content = Buffer.from(base64Data, 'base64');
await fs.writeFile(fullPath, content);
logger.debug(`Wrote ${content.length} bytes to ${fullPath}`);
};
async function patchApksigner (originalPath) {
const originalContent = await fs.readFile(originalPath, 'ascii');
const patchedContent = originalContent.replace('-Djava.ext.dirs="%frameworkdir%"',
'-cp "%frameworkdir%\\*"');
if (patchedContent === originalContent) {
return originalPath;
}
log.debug(`Patching '${originalPath}...`);
const patchedPath = await tempDir.path({prefix: 'apksigner', suffix: '.bat'});
await mkdirp(path.dirname(patchedPath));
await fs.writeFile(patchedPath, patchedContent, 'ascii');
return patchedPath;
}