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

[kbnArchiver] fix save to non-existent file #101974

Merged
merged 1 commit into from
Jun 11, 2021
Merged
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
12 changes: 9 additions & 3 deletions packages/kbn-test/src/kbn_client/kbn_client_import_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export class KbnClientImportExport {
path = `${path}.json`;
}

const absolutePath = Path.resolve(this.baseDir, path);
return Path.resolve(this.baseDir, path);
}

private resolveAndValidatePath(path: string) {
const absolutePath = this.resolvePath(path);

if (!existsSync(absolutePath)) {
throw new Error(
`unable to resolve path [${path}] to import/export, resolved relative to [${this.baseDir}]`
Expand All @@ -59,7 +64,7 @@ export class KbnClientImportExport {
}

async load(path: string, options?: { space?: string }) {
const src = this.resolvePath(path);
const src = this.resolveAndValidatePath(path);
this.log.debug('resolved import for', path, 'to', src);

const objects = await parseArchive(src);
Expand Down Expand Up @@ -94,7 +99,7 @@ export class KbnClientImportExport {
}

async unload(path: string, options?: { space?: string }) {
const src = this.resolvePath(path);
const src = this.resolveAndValidatePath(path);
this.log.debug('unloading docs from archive at', src);

const objects = await parseArchive(src);
Expand Down Expand Up @@ -143,6 +148,7 @@ export class KbnClientImportExport {
})
.join('\n\n');

await Fs.mkdir(Path.dirname(dest), { recursive: true });
await Fs.writeFile(dest, fileContents, 'utf-8');

this.log.success('Exported', objects.length, 'saved objects to', dest);
Expand Down