Skip to content

Commit

Permalink
fix: moving of files to destination folder now works across filesyste…
Browse files Browse the repository at this point in the history
…m boundaries

Signed-off-by: Gustav Grusell <[email protected]>
  • Loading branch information
grusell committed Jun 18, 2024
1 parent 63391e8 commit 4a6d3cf
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 22 deletions.
92 changes: 75 additions & 17 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@types/jest": "^29.5.11",
"@types/mv": "^2.1.4",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
Expand All @@ -35,6 +36,7 @@
"typescript": "^4.9.5"
},
"dependencies": {
"commander": "^12.1.0"
"commander": "^12.1.0",
"mv": "^2.1.1"
}
}
19 changes: 15 additions & 4 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spawnSync } from 'node:child_process';
import { existsSync, mkdirSync } from 'node:fs';
import { readdir, rename, mkdir } from 'node:fs/promises';
import { toUrl, toUrlOrUndefined } from './util';
import mv from 'mv';

const DEFAULT_STAGING_DIR = '/tmp/data';

Expand Down Expand Up @@ -75,13 +76,19 @@ export async function download(
}
}

async function moveFile(src: string, dest: string) {
return new Promise((resolve, reject) => {
mv(src, dest, (err) => (err ? reject(err) : resolve(dest)));
});
}

export async function uploadPackage(dest: URL, stagingDir: string) {
if (!dest.protocol || dest.protocol === 'file:') {
await mkdir(dest.pathname, { recursive: true });
const files = await readdir(stagingDir);
await Promise.all(
files.map((file) =>
rename(join(stagingDir, file), join(dest.pathname, file))
moveFile(join(stagingDir, file), join(dest.pathname, file))
)
);
return;
Expand Down Expand Up @@ -122,12 +129,16 @@ export async function createPackage(opts: PackageOptions) {
const args = createShakaArgs(downloadedInputs, noImplicitAudio === true);
console.log(args);
const shaka = opts.shakaExecutable || 'packager';
const { status, stderr } = spawnSync(shaka, args, {
const { status, stderr, error } = spawnSync(shaka, args, {
cwd: stagingDir
});
if (status !== 0) {
console.log(`Packager failed with exit code ${status}`);
console.log(stderr.toString());
if (error) {
console.error(`Packager failed: ${error.message}`);
} else {
console.error(`Packager failed with exit code ${status}`);
console.error(stderr.toString());
}
throw new Error('Packager failed');
}
}
Expand Down

0 comments on commit 4a6d3cf

Please sign in to comment.