Skip to content

Commit

Permalink
fix errors when specifying zip path with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Sep 26, 2024
1 parent 5ef1497 commit 2d269fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/cli/CLICommand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as child_process from 'node:child_process';

export interface CLICommand {

Expand All @@ -7,3 +8,15 @@ export interface CLICommand {
run(argv: string[]): Promise<any>;

}

export function processSpawnResult(result : child_process.SpawnSyncReturns<Buffer>) {
if (result.error !== undefined) {
throw result.error;
}
if (result.signal !== null) {
throw Error(`Child process has been killed by signal ${result.signal}`);
}
if (result.status !== null && result.status !== 0) {
throw Error(`Child process exited with non-zero status ${result.status}`);
}
}
8 changes: 4 additions & 4 deletions src/cli/OutputGTFSZipCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import * as os from 'node:os';
import * as path from 'node:path';
import {CLICommand} from "./CLICommand";
import {CLICommand, processSpawnResult} from "./CLICommand";
import {OutputGTFSCommand} from "./OutputGTFSCommand";
import * as fs from "fs";
import {execSync} from "child_process";
import {spawnSync} from "child_process";

export class OutputGTFSZipCommand implements CLICommand {

Expand All @@ -29,8 +29,8 @@ export class OutputGTFSZipCommand implements CLICommand {
// when node tells you it's finished writing a file, it's lying.
setTimeout(() => {
console.log("Writing " + filename);
execSync(`zip -j ${filename} ${argv[3]}/*.txt`);
processSpawnResult(spawnSync('zip', ['-jr', filename, argv[3]]));
}, 1000);
}

}
}

0 comments on commit 2d269fc

Please sign in to comment.