Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const lvlPair = args.loglevel.split(':');
consoleLogLevel = lvlPair[0] || consoleLogLevel;
fileLogLevel = lvlPair[1] || fileLogLevel;
} else {
consoleLogLevel = fileLogLevel = args.loglevel;
}
transports.push(createConsoleTransport(args, consoleLogLevel));
if (args.logFile) {
try {
// if we don't delete the log file, winston will always append and it will grow infinitely large;
// winston allows for limiting log file size, but as of 9.2.14 there's a serious bug when using
// maxFiles and maxSize together. https://github.com/flatiron/winston/issues/397
if (await fs.exists(args.logFile)) {
await fs.unlink(args.logFile);
}
transports.push(createFileTransport(args, fileLogLevel));
} catch (e) {
// eslint-disable-next-line no-console
console.log(`Tried to attach logging to file '${args.logFile}' but an error ` +
`occurred: ${e.message}`);
}
}
if (args.webhook) {
try {
transports.push(createHttpTransport(args, fileLogLevel));
} catch (e) {
// eslint-disable-next-line no-console
console.log(`Tried to attach logging to Http at ${args.webhook} but ` +
afterEach(async function () {
if (await fs.exists(tmpFile1)) {
await fs.unlink(tmpFile1);
}
if (await fs.exists(tmpFile2)) {
await fs.unlink(tmpFile2);
}
});
afterEach(async () => {
await fs.unlink(tmpPlist);
});
}
let remotePath = `/data/data/${this.opts.appPackage}/shared_prefs`;
let remoteFile = `${remotePath}/${name}.xml`;
let localPath = `/tmp/${name}.xml`;
let builder = this.getPrefsBuilder();
builder.build(sharedPrefs.prefs);
log.info(`Creating temporary shared preferences: ${localPath}`);
builder.toFile(localPath);
log.info(`Creating shared_prefs remote folder: ${remotePath}`);
await this.adb.shell(['mkdir', '-p', remotePath]);
log.info(`Pushing shared_prefs to ${remoteFile}`);
await this.adb.push(localPath, remoteFile);
try {
log.info(`Trying to remove shared preferences temporary file`);
if (await fs.exists(localPath)) {
await fs.unlink(localPath);
}
} catch (e) {
log.warn(`Error trying to remove temporary file ${localPath}`);
}
return true;
}
async function getScreenshotData (sdb) {
const rootDir = path.resolve(__dirname, '..', '..');
const filePath = path.resolve(rootDir, 'file');
let localFile = filePath + '/screenShot.tmp';
if (await fs.exists(localFile)) {
await fs.unlink(localFile);
}
try {
const pngDir = '/tmp/';
const png = path.posix.resolve(pngDir, 'dump_screen.png');
await sdb.pull(png, localFile);
return await jimp.read(localFile);
} finally {
if (await fs.exists(localFile)) {
await fs.unlink(localFile);
}
}
}
await this.adb.shell(['run-as', packageId, `chmod 777 '${pathInContainer.replace(/'/g, '\\\'')}'`]);
await this.adb.shell(['cp', '-f', pathInContainer, tmpDestination]);
} catch (e) {
log.errorAndThrow(`Cannot access the container of '${packageId}' application. ` +
`Is the application installed and has 'debuggable' build option set to true? ` +
`Original error: ${e.message}`);
}
}
const localFile = await tempDir.path({prefix: 'appium', suffix: '.tmp'});
try {
await this.adb.pull(_.isString(tmpDestination) ? tmpDestination : remotePath, localFile);
const data = await fs.readFile(localFile);
return Buffer.from(data).toString('base64');
} finally {
if (await fs.exists(localFile)) {
await fs.unlink(localFile);
}
if (_.isString(tmpDestination)) {
await this.adb.shell(['rm', '-f', tmpDestination]);
}
}
};
try {
return await getApksignerOutput(apkSigner);
} catch (err) {
log.warn(`Got an error during apksigner execution: ${err.message}`);
for (const [name, stream] of [['stdout', err.stdout], ['stderr', err.stderr]]) {
if (stream) {
log.warn(`apksigner ${name}: ${stream}`);
}
}
if (system.isWindows()) {
const patchedApksigner = await patchApksigner(apkSigner);
if (patchedApksigner !== apkSigner) {
try {
return await getApksignerOutput(patchedApksigner);
} finally {
await fs.unlink(patchedApksigner);
}
}
}
throw err;
}
};