Skip to content

Commit

Permalink
Improve gtfs zip output robustness
Browse files Browse the repository at this point in the history
- Clear /tmp/gtfs before running OutputGTFSCommand
- Log errors from running zip command
  • Loading branch information
dzfranklin committed Aug 5, 2024
1 parent a78992b commit 1a0d400
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/cli/OutputGTFSZipCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
import {CLICommand} from "./CLICommand";
import {OutputGTFSCommand} from "./OutputGTFSCommand";
import * as fs from "fs";
import {execSync} from "child_process";
import { execSync } from "child_process";
import * as path from "path";

export class OutputGTFSZipCommand implements CLICommand {

constructor(
private readonly command: OutputGTFSCommand
) { }
constructor(private readonly command: OutputGTFSCommand) {}

/**
* Create the text files and then zip them up using a CLI command that hopefully exists.
Expand All @@ -22,7 +20,11 @@ export class OutputGTFSZipCommand implements CLICommand {

argv[3] = "/tmp/gtfs/";

if (!fs.existsSync(argv[3])) {
if (fs.existsSync(argv[3])) {
for (const entry of fs.readdirSync(argv[3])) {
fs.rmSync(path.join(argv[3], entry), { recursive: true });
}
} else {
fs.mkdirSync(argv[3]);
}

Expand All @@ -31,8 +33,16 @@ 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`);
try {
execSync(`zip -j ${filename} ${argv[3]}/*.txt`);
} catch (err) {
const dec = new TextDecoder();
console.error("STDOUT:");
console.error(dec.decode(err.stdout));
console.error("STDERR:");
console.error(dec.decode(err.stderr));
throw err;
}
}, 1000);
}

}
}

0 comments on commit 1a0d400

Please sign in to comment.