Skip to content

Commit

Permalink
Use tempy for temporary directory creation
Browse files Browse the repository at this point in the history
  • Loading branch information
brendannee committed Jun 17, 2024
1 parent f147e13 commit bed71f9
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Support for `service_id` in `getRoutes`

### Changed

- Use tempy for temporary directory creation

## [4.11.3] - 2024-06-13

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions lib/import.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'node:path';
import { createReadStream, existsSync, lstatSync } from 'node:fs';
import { cp, readdir, rename, readFile, writeFile } from 'node:fs/promises';
import { cp, readdir, rename, readFile, rm, writeFile } from 'node:fs/promises';
import fetch from 'node-fetch';
import { parse } from 'csv-parse';
import pluralize from 'pluralize';
import stripBomStream from 'strip-bom-stream';
import { dir } from 'tmp-promise';
import { temporaryDirectory } from 'tempy';
import untildify from 'untildify';
import mapSeries from 'promise-map-series';
import GtfsRealtimeBindings from 'gtfs-realtime-bindings';
Expand Down Expand Up @@ -687,15 +687,15 @@ export async function importGtfs(initialConfig) {
createTables(db);

await mapSeries(config.agencies, async (agency) => {
const { path, cleanup } = await dir({ unsafeCleanup: true });
const tempPath = temporaryDirectory();

const task = {
exclude: agency.exclude,
agency_url: agency.url,
headers: agency.headers || false,
realtime_headers: agency.realtimeHeaders || false,
realtime_urls: agency.realtimeUrls || false,
downloadDir: path,
downloadDir: tempPath,
downloadTimeout: config.downloadTimeout,
path: agency.path,
csvOptions: config.csvOptions || {},
Expand All @@ -719,7 +719,7 @@ export async function importGtfs(initialConfig) {
await updateRealtimeData(task);
}

cleanup();
await rm(tempPath, { recursive: true });
} catch (error) {
if (config.ignoreErrors) {
logError(error.message);
Expand Down
99 changes: 85 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"sanitize-filename": "^1.6.3",
"sqlstring-sqlite": "^0.1.1",
"strip-bom-stream": "^5.0.0",
"tmp-promise": "^3.0.3",
"tempy": "^3.1.0",
"untildify": "^5.0.0",
"yargs": "^17.7.2",
"yoctocolors": "^2.0.2"
Expand Down

0 comments on commit bed71f9

Please sign in to comment.