Support for pre-compiled 7z/unzip

pull/153/head
Piero Toffanin 2021-05-24 11:19:16 -04:00
rodzic e30718c567
commit 90ecdb4c34
4 zmienionych plików z 42 dodań i 5 usunięć

1
.gitignore vendored
Wyświetl plik

@ -43,3 +43,4 @@ jspm_packages
.vscode
package-lock.json
apps/

Wyświetl plik

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
let fs = require('fs');
let argv = require('minimist')(process.argv.slice(2));
let utils = require('./libs/utils');
let apps = require('./libs/apps');
const spawnSync = require('child_process').spawnSync;
if (argv.help){
@ -141,8 +142,8 @@ config.maxConcurrency = parseInt(argv.max_concurrency || fromConfigFile("maxConc
config.maxRuntime = parseInt(argv.max_runtime || fromConfigFile("maxRuntime", -1));
// Detect 7z availability
config.has7z = spawnSync("7z", ['--help']).status === 0;
config.hasUnzip = spawnSync("unzip", ['--help']).status === 0;
config.has7z = spawnSync(apps.sevenZ, ['--help']).status === 0;
config.hasUnzip = spawnSync(apps.unzip, ['--help']).status === 0;
module.exports = config;

34
libs/apps.js 100644
Wyświetl plik

@ -0,0 +1,34 @@
/*
Node-OpenDroneMap Node.js App and REST API to access OpenDroneMap.
Copyright (C) 2016 Node-OpenDroneMap Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const fs = require('fs');
const path = require('path');
let sevenZ = "7z";
let unzip = "unzip";
if (fs.existsSync(path.join("apps", "7z", "7z.exe"))){
sevenZ = path.resolve(path.join("apps", "7z", "7z.exe"));
}
if (fs.existsSync(path.join("apps", "unzip", "unzip.exe"))){
unzip = path.resolve(path.join("apps", "unzip", "unzip.exe"));
}
module.exports = {
sevenZ, unzip
};

Wyświetl plik

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
let fs = require('fs');
let apps = require('./apps');
let path = require('path');
let assert = require('assert');
let spawn = require('child_process').spawn;
@ -92,14 +93,14 @@ module.exports = {
},
["projectFolderPath"]),
sevenZip: makeRunner("7z", function(options){
sevenZip: makeRunner(apps.sevenZ, function(options){
return ["a", "-mx=0", "-y", "-r", "-bd", options.destination].concat(options.pathsToArchive);
},
["destination", "pathsToArchive", "cwd"],
null,
false),
sevenUnzip: makeRunner("7z", function(options){
sevenUnzip: makeRunner(apps.sevenZ, function(options){
let cmd = "x"; // eXtract files with full paths
if (options.noDirectories) cmd = "e"; //Extract files from archive (without using directory names)
@ -109,7 +110,7 @@ module.exports = {
null,
false),
unzip: makeRunner("unzip", function(options){
unzip: makeRunner(apps.unzip, function(options){
const opts = options.noDirectories ? ["-j"] : [];
return opts.concat(["-qq", "-o", options.file, "-d", options.destination]);
},