Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
name = name.replace(/\\/g, '/');
if (name.indexOf('/') == -1) {
name = getBackupDir() + name;
var regEx = new RegExp('_backup' + tools.appName, 'i');
if (!regEx.test(name)) name += '_backup' + tools.appName;
if (!name.match(/\.tar\.gz$/i)) name += '.tar.gz';
}
if (!fs.existsSync(name)) {
console.log('Cannot find ' + name);
processExit(11);
}
var TARgz = require('tar.gz');
if (fs.existsSync(__dirname + '/../tmp/backup/backup.json')) fs.unlinkSync(__dirname + '/../tmp/backup/backup.json');
new TARgz().extract(name, __dirname + '/../tmp', function (err) {
if (err) {
console.log('Cannot extract from file "' + name + '"');
processExit(9);
}
if (!fs.existsSync(__dirname + '/../tmp/backup/backup.json')) {
console.log('Cannot find extracted file from file /../tmp/backup/backup.json"');
processExit(9);
}
// Stop controller
var daemon = require('daemonize2').setup({
main: '../controller.js',
name: tools.appName + ' controller',
pidfile: __dirname + '/' + tools.appName + '.pid',
cwd: '../',
stopTimeout: 1000
});
targzAction() {
// Streams
if (this.isGet()) {
let paths = think.RESOURCE_PATH;
let path = "/backup/";
let dir = paths + path + this.get("dir");
let tar = paths + path + this.get("dir") + ".tar.gz"
if (!think.isFile(tar)) {
//var read = targz().createReadStream(dir);
//var parse = fs.createWriteStream(tar);
//read.pipe(parse);
let self = this;
targz().compress(dir, tar)
.then(function () {
self.success({'name': "tar", 'url': self.get("dir")})
})
.catch(function (err) {
console.log('Something is wrong ', err.stack);
});
} else {
this.success({'name': "download", 'url': this.get("dir")})
}
} else if (this.isPost()) {
let paths = think.RESOURCE_PATH;
let path = "/backup/";
let tar = paths + path + this.post("name") + ".tar.gz"
this.download(tar);
}
}), function (file, cb) {
var archive = Path.join(self.modulePath, file);
file = file.replace(/\.tgz$/i, '');
var name = file.substring(0, file.lastIndexOf(sep));
var version = file.substring(file.lastIndexOf(sep) + sep.length);
if (deps[name]) {
// remove existing installed module
rimraf.sync(Path.join(destPath, name));
// extract the module into node_modules
new tgz().extract(archive, destPath, function (err) {
if (!err) {
log('Extracted', name + '@' + version);
} else {
error(err);
}
cb();
});
} else {
cb();
}
}, function () {
log('\nDone!');
// Contents have not changed in size since the previous
// iteration. Done!
callback();
} else {
// Contents have changed. Note the new size, delay a
// moment, and then check again.
prevSize = totalSize;
setTimeout(checkIfDone,250);
}
})
.on("error",function(err){
return callback(err);
});
};
new targz().extract(source,target,checkIfDone);
};
async.eachSeries(glob.sync('*.tgz', {cwd:modulePath}), function(file, cb) {
var archive = Path.join(modulePath, file)
file = file.replace(/\.tgz$/i, '')
var name = file.substring(0, file.lastIndexOf(sep))
var version = file.substring(file.lastIndexOf(sep)+sep.length)
// remove existing installed module
if (fs.existsSync(Path.join(nodeModulesPath, name))) {
fs.rmdirSync(Path.join(nodeModulesPath, name))
}
// extract the module into node_modules
new tgz().extract(archive, nodeModulesPath, function(err) {
if (!err) log('Extracted', name+'@'+version)
else error(err)
cb()
})
}, function() {
log('Done! Now run \'npm rebuild\'')
function processArchive() {
var targz = require("tar.gz");
console.log("Unzip archive '%s'", zfile);
var tgz = new targz();
tgz.extract(zfile, sdir, function(err){
if (err) {
console.log(err);
process.exit(1);
return;
}
sdir = path.resolve(sdir);
var config = {};
config["variables"] = {
"EJDB_HOME" : sdir
};
fs.writeFileSync("configure.gypi", JSON.stringify(config));
var args = ["configure", "rebuild"];
var extractChromedriver = function(cbdone) {
grunt.log.writeln('Extracting node-webkit chromedriver.');
if (config.platform === 'linux') {
var targz = require('tar.gz');
var compress = new targz().extract(chromeDriverLocal, support_dir, function(err) {
if(err)
console.log(err);
var cdSrc = path.resolve(chromeDriverLocal.replace(/\.tar\.gz$/, ''), 'chromedriver');
fs.renameSync(cdSrc, chromeDriverFile);
grunt.log.writeln('e2e setup is complete.');
cbdone();
});
} else {
fs.createReadStream(chromeDriverLocal)
.pipe(unzip.Parse())
.on('entry', function (entry) {
if (entry.path.indexOf('/chromedriver') >= 0) {
entry.pipe(fs.createWriteStream(chromeDriverFile));
} else {
entry.autodrain();
packager(Object.assign({}, all, linux), function (err, buildPath) {
if (err) return cb(err);
console.log('Linux: Packaged electron. ' + buildPath);
var targetPath = path.join(DIST_PATH, BUILD_NAME + '_linux-x64.tar.gz');
rimraf.sync(targetPath);
targz().compress(buildPath[0], targetPath).then(function() {
console.log('Linux: Created tarball ' + targetPath);
}).catch(cb);
})
}
const buildTarGzArchive = ({lookupDir, archiveFilePath}) => {
let gzipOptions = {
level : 9,
memLevel : 9,
};
let tarOptions = {
fromBase : true
};
return new TarGz(gzipOptions, tarOptions)
.compress(lookupDir, archiveFilePath)
.then(() => archiveFilePath);
};
return new Promise(function (resolve, reject) {
var path = null;
var targz = require('tar.gz');
new targz({}, {fromBase: true}).compress(Pencil.documentHandler.tempDir.name, documentPath)
.then(resolve).catch(reject);
});
};