Skip to content

Commit

Permalink
fix: sort file arguments to tar file-list
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Scheirlinck committed Jan 12, 2022
1 parent d3ac439 commit ae6949f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/artifacts/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ export async function filesToUpload({
}

await Promise.all(matching);
return matched.matched;
return matched.matched.sort();
}
16 changes: 4 additions & 12 deletions src/commands/upload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { flags as f } from '@oclif/command';
import debug from 'debug';
import execa from 'execa';
import { upload } from '../artifacts/api';
import { deflateCmd } from '../artifacts/compression';
import { filesToUpload } from '../artifacts/matcher';
Expand Down Expand Up @@ -102,22 +101,15 @@ locally cached
return;
}

if (flags.verbose) {
log('Files to upload', files);
}

log(`Uploading ${count(files, 'path')} as ${args.output}`);
log(`Uploading ${count(files, 'path')} as ${args.output}`, files);

const tarBin = await tar();
const tarArgs = ['-c', '--null', '--files-from', '-'];

const allArgs: string[] = ['-o', 'pipefail', ';', tarBin, ...tarArgs, '|', ...(await deflateCmd(artifact))];
const input = `${files.join('\x00')}\x00`;

log(`Going to deflate, using set ${allArgs.join(' ')} < files-to-upload`);

await execa('set', allArgs, {
input: stream.Readable.from(files.join('\x00')),
shell: 'bash',
await exec('set', allArgs, {
input,
});

log(`Archive deflated at ${args.output}`);
Expand Down
31 changes: 30 additions & 1 deletion test/commands/upload.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import { promisify } from 'util';
import mkdirp from 'mkdirp';
import tempy from 'tempy';
import { upload } from '../../src/artifacts/api';
import Upload from '../../src/commands/upload';
Expand Down Expand Up @@ -31,7 +32,7 @@ describe('cmd upload', () => {

await writeFile(`${dir}/foo.txt`, 'bar');
await writeFile(`${dir}/bar.txt`, 'baz');
await writeFile(`${dir}/file-list.null.txt`, 'foo.txt\x00bar.txt');
await writeFile(`${dir}/file-list.null.txt`, 'foo.txt\x00bar.txt\x00');

const { stderr } = await testRun(Upload, [
'--null',
Expand All @@ -44,6 +45,34 @@ describe('cmd upload', () => {
});
});

it('can upload a list of directories in the right order, null separated', async () => {
await tempy.directory.task(async (dir) => {
process.chdir(dir);

await mkdirp(`${dir}/foo/bar`);
await mkdirp(`${dir}/foo/baz`);
+(await writeFile(`${dir}/foo/bar/a.txt`, 'a'));
await writeFile(`${dir}/foo/bar/b.txt`, 'b');
await writeFile(`${dir}/foo/baz/a.txt`, 'a');
await writeFile(`${dir}/foo/baz/b.txt`, 'b');
await writeFile(`${dir}/foo/a.txt`, 'a');
await writeFile(`${dir}/foo/b.txt`, 'b');

// This file list is in the wrong order! https://github.com/folbricht/desync/issues/210
await writeFile(`${dir}/file-list.null.txt`, './foo/bar\x00./foo/\x00./foo/baz/\x00');

const { stderr } = await testRun(Upload, [
'--null',
'--files-from',
`${dir}/file-list.null.txt`,
'some-upload.tar.gz',
]);

expect(stderr).toContain("Uploading 3 paths as some-upload.tar.gz [ './foo/', './foo/bar', './foo/baz/' ]");
expect(stderr).toContain('Successfully uploaded some-upload');
});
});

it('can upload a with globs', async () => {
await tempy.directory.task(async (dir: string) => {
process.chdir(dir);
Expand Down

0 comments on commit ae6949f

Please sign in to comment.