Skip to content

Commit

Permalink
feat(cli): keep temp files in verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Oct 4, 2024
1 parent ed78354 commit c534a37
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/actions/BackupAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class BackupAction {
}
async exec() {
const { options, settings } = this;
const gc = new GargabeCollector();
const gc = new GargabeCollector(this.options.verbose);
const pm = new ProgressManager({
verbose: options.verbose,
tty: settings.tty,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/actions/ExportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ExportAction {
}
async exec() {
const { options, settings } = this;
const gc = new GargabeCollector();
const gc = new GargabeCollector(this.options.verbose);
const pm = new ProgressManager({
verbose: options.verbose,
tty: settings.tty,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/actions/RestoreAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class RestoreAction {
}
async exec() {
const { options, settings } = this;
const gc = new GargabeCollector();
const gc = new GargabeCollector(this.options.verbose);
const pm = new ProgressManager({
verbose: options.verbose,
tty: settings.tty,
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/utils/temp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function useTempFile(path: string): AsyncDisposable & { path: string } {
export class GargabeCollector {
readonly paths: Set<string> = new Set();
readonly children: Set<GargabeCollector> = new Set();
constructor(protected parent?: GargabeCollector) {
constructor(protected verbose?: boolean) {
collectors.add(this);
}
pending() {
Expand All @@ -93,7 +93,7 @@ export class GargabeCollector {
async cleanup() {
for (const path of this.paths) {
try {
await rmTmpDir(path);
if (!this.verbose) await rmTmpDir(path);
this.paths.delete(path);
} catch (_) {}
}
Expand All @@ -119,7 +119,7 @@ export class GargabeCollector {
};
}
create() {
const gc = new GargabeCollector();
const gc = new GargabeCollector(this.verbose);
this.children.add(gc);
return gc;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/test/utils/temp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ describe("GargabeCollector", () => {
expect(gc.paths.size).toBe(0);
await expectDir(path2, false);
});

it("cleanup is disabled", async () => {
const gc = new GargabeCollector(true);
const path1 = await mkTmpDir("1");
await expectDir(path1);
expect(gc.paths.size).toBe(1);
await gc.cleanup();
await expectDir(path1, true);
expect(gc.paths.size).toBe(0);
});
it("dispose", async () => {
const gc = new GargabeCollector();
const path1 = await mkTmpDir("1");
Expand Down

0 comments on commit c534a37

Please sign in to comment.