Attempt to detect when an archiver does not exist (HACK!)
This commit is contained in:
parent
9af9bfe3d0
commit
26fb4692dc
|
@ -2,12 +2,12 @@
|
|||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
let Config = require('./config.js').config;
|
||||
const Config = require('./config.js').config;
|
||||
|
||||
// base/modules
|
||||
let fs = require('fs');
|
||||
let _ = require('lodash');
|
||||
let pty = require('ptyw.js');
|
||||
const fs = require('fs');
|
||||
const _ = require('lodash');
|
||||
const pty = require('ptyw.js');
|
||||
|
||||
module.exports = class ArchiveUtil {
|
||||
|
||||
|
@ -74,15 +74,14 @@ module.exports = class ArchiveUtil {
|
|||
let buf = new Buffer(this.longestSignature);
|
||||
fs.read(fd, buf, 0, buf.length, 0, (err, bytesRead) => {
|
||||
if(err) {
|
||||
cb(err);
|
||||
return;
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// return first match
|
||||
const detected = _.findKey(this.archivers, arch => {
|
||||
const lenNeeded = arch.offset + arch.sig.length;
|
||||
|
||||
if(buf.length < lenNeeded) {
|
||||
if(bytesRead < lenNeeded) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -95,6 +94,27 @@ module.exports = class ArchiveUtil {
|
|||
});
|
||||
}
|
||||
|
||||
spawnHandler(comp, action, cb) {
|
||||
// pty.js doesn't currently give us a error when things fail,
|
||||
// so we have this horrible, horrible hack:
|
||||
let err;
|
||||
comp.once('data', d => {
|
||||
if(_.isString(d) && d.startsWith('execvp(3) failed.: No such file or directory')) {
|
||||
err = new Error(`${action} failed: ${d.trim()}`);
|
||||
}
|
||||
});
|
||||
|
||||
comp.once('exit', exitCode => {
|
||||
if(exitCode) {
|
||||
return cb(new Error(`${action} failed with exit code: ${exitCode}`));
|
||||
}
|
||||
if(err) {
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
|
||||
compressTo(archType, archivePath, files, cb) {
|
||||
const archiver = this.getArchiver(archType);
|
||||
|
||||
|
@ -112,9 +132,7 @@ module.exports = class ArchiveUtil {
|
|||
|
||||
let comp = pty.spawn(archiver.compressCmd, args, this.getPtyOpts());
|
||||
|
||||
comp.once('exit', exitCode => {
|
||||
cb(exitCode ? new Error(`Compression failed with exit code: ${exitCode}`) : null);
|
||||
});
|
||||
return this.spawnHandler(comp, 'Compression', cb);
|
||||
}
|
||||
|
||||
extractTo(archivePath, extractPath, archType, cb) {
|
||||
|
@ -133,10 +151,8 @@ module.exports = class ArchiveUtil {
|
|||
}
|
||||
|
||||
let comp = pty.spawn(archiver.decompressCmd, args, this.getPtyOpts());
|
||||
|
||||
comp.once('exit', exitCode => {
|
||||
cb(exitCode ? new Error(`Decompression failed with exit code: ${exitCode}`) : null);
|
||||
});
|
||||
|
||||
return this.spawnHandler(comp, 'Decompression', cb);
|
||||
}
|
||||
|
||||
getPtyOpts() {
|
||||
|
@ -148,4 +164,4 @@ module.exports = class ArchiveUtil {
|
|||
env : process.env,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue