Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use unique temp directory #99

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/cli/Container.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import * as memoize from "memoized-class-decorator";
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import {CLICommand} from "./CLICommand";
import {ImportFeedCommand} from "./ImportFeedCommand";
import {DatabaseConfiguration, DatabaseConnection} from "../database/DatabaseConnection";
Expand Down Expand Up @@ -45,22 +48,22 @@ export class Container {

@memoize
public async getFaresImportCommand(): Promise<ImportFeedCommand> {
return new ImportFeedCommand(await this.getDatabaseConnection(), config.fares, "/tmp/dtd/fares/");
return new ImportFeedCommand(await this.getDatabaseConnection(), config.fares, fs.mkdtempSync(path.join(os.tmpdir(), "dtd")));
}

@memoize
public async getRouteingImportCommand(): Promise<ImportFeedCommand> {
return new ImportFeedCommand(await this.getDatabaseConnection(), config.routeing, "/tmp/dtd/routeing/");
return new ImportFeedCommand(await this.getDatabaseConnection(), config.routeing, fs.mkdtempSync(path.join(os.tmpdir(), "dtd")));
}

@memoize
public async getTimetableImportCommand(): Promise<ImportFeedCommand> {
return new ImportFeedCommand(await this.getDatabaseConnection(), config.timetable, "/tmp/dtd/timetable/");
return new ImportFeedCommand(await this.getDatabaseConnection(), config.timetable, fs.mkdtempSync(path.join(os.tmpdir(), "dtd")));
}

@memoize
public async getNFM64ImportCommand(): Promise<ImportFeedCommand> {
return new ImportFeedCommand(await this.getDatabaseConnection(), config.nfm64, "/tmp/dtd/nfm64/");
return new ImportFeedCommand(await this.getDatabaseConnection(), config.nfm64, fs.mkdtempSync(path.join(os.tmpdir(), "dtd")));
}


Expand Down
2 changes: 1 addition & 1 deletion src/cli/ImportFeedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class ImportFeedCommand implements CLICommand {
const file = this.getFeedFile(filename);
const tables = await this.tables(file);
const tableStream = new MySQLStream(filename, file, tables);
const stream = readFile(this.tmpFolder + filename).pipe(tableStream);
const stream = readFile(`${this.tmpFolder}/${filename}`).pipe(tableStream);

try {
await streamToPromise(stream);
Expand Down
10 changes: 5 additions & 5 deletions src/cli/OutputGTFSCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class OutputGTFSCommand implements CLICommand {
* Turn the timetable feed into GTFS files
*/
public async run(argv: string[]): Promise<void> {
this.baseDir = argv[3] || "./";
this.baseDir = argv[3] || ".";

if (!fs.existsSync(this.baseDir)) {
throw new Error(`Output path ${this.baseDir} does not exist.`);
Expand Down Expand Up @@ -63,7 +63,7 @@ export class OutputGTFSCommand implements CLICommand {
*/
private async copy(results: object[] | Promise<object[]>, filename: string): Promise<void> {
const rows = await results;
const output = this.output.open(this.baseDir + filename);
const output = this.output.open(`${this.baseDir}/filename`);

console.log("Writing " + filename);
rows.forEach(row => output.write(row));
Expand All @@ -77,9 +77,9 @@ export class OutputGTFSCommand implements CLICommand {
*/
private copyTrips(schedules: Schedule[], serviceIds: ServiceIdIndex): Promise<any> {
console.log("Writing trips.txt, stop_times.txt and routes.txt");
const trips = this.output.open(this.baseDir + "trips.txt");
const stopTimes = this.output.open(this.baseDir + "stop_times.txt");
const routeFile = this.output.open(this.baseDir + "routes.txt");
const trips = this.output.open(`${this.baseDir}/trips.txt`);
const stopTimes = this.output.open(`${this.baseDir}/stop_times.txt`);
const routeFile = this.output.open(`${this.baseDir}/routes.txt`);
const routes = {};

for (const schedule of schedules) {
Expand Down
10 changes: 4 additions & 6 deletions src/cli/OutputGTFSZipCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import * as os from 'node:os';
import * as path from 'node:path';
import {CLICommand} from "./CLICommand";
import {OutputGTFSCommand} from "./OutputGTFSCommand";
import * as fs from "fs";
Expand All @@ -19,12 +21,8 @@ export class OutputGTFSZipCommand implements CLICommand {
if (fs.existsSync(filename)) {
fs.unlinkSync(filename);
}

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

if (!fs.existsSync(argv[3])) {
fs.mkdirSync(argv[3]);
}

argv[3] = fs.mkdtempSync(path.join(os.tmpdir(), "gtfs"));

await this.command.run(argv);

Expand Down
Loading