@datatruck/cli 0.16.0 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/Action/BackupAction.d.ts +21 -5
  2. package/Action/BackupAction.js +64 -37
  3. package/Action/BackupSessionsAction.d.ts +1 -1
  4. package/Action/CleanCacheAction.d.ts +1 -1
  5. package/Action/ConfigAction.d.ts +1 -1
  6. package/Action/InitAction.d.ts +1 -1
  7. package/Action/PruneAction.d.ts +2 -2
  8. package/Action/RestoreAction.d.ts +12 -6
  9. package/Action/RestoreAction.js +26 -12
  10. package/Action/RestoreSessionsAction.d.ts +1 -1
  11. package/Action/SnapshotsAction.d.ts +3 -3
  12. package/Command/BackupCommand.d.ts +1 -1
  13. package/Command/BackupSessionsCommand.d.ts +1 -1
  14. package/Command/CleanCacheCommand.d.ts +1 -1
  15. package/Command/CommandAbstract.d.ts +2 -2
  16. package/Command/ConfigCommand.d.ts +2 -2
  17. package/Command/InitCommand.d.ts +2 -2
  18. package/Command/PruneCommand.d.ts +1 -1
  19. package/Command/RestoreCommand.d.ts +1 -1
  20. package/Command/RestoreSessionsCommand.d.ts +1 -1
  21. package/Command/SnapshotsCommand.d.ts +2 -2
  22. package/Config/Config.d.ts +1 -1
  23. package/Config/PackageConfig.d.ts +2 -2
  24. package/Config/PackageRepositoryConfig.d.ts +1 -1
  25. package/Config/PrunePolicyConfig.d.ts +1 -1
  26. package/Config/RepositoryConfig.d.ts +3 -3
  27. package/Config/TaskConfig.d.ts +1 -1
  28. package/Decorator/EntityDecorator.d.ts +1 -1
  29. package/Factory/CommandFactory.d.ts +2 -2
  30. package/Repository/DatatruckRepository.d.ts +4 -4
  31. package/Repository/DatatruckRepository.js +21 -18
  32. package/Repository/GitRepository.d.ts +2 -2
  33. package/Repository/GitRepository.js +3 -3
  34. package/Repository/RepositoryAbstract.d.ts +11 -9
  35. package/Repository/RepositoryAbstract.js +7 -0
  36. package/Repository/ResticRepository.d.ts +2 -2
  37. package/Repository/ResticRepository.js +3 -1
  38. package/SessionDriver/ConsoleSessionDriver.d.ts +3 -3
  39. package/SessionDriver/SessionDriverAbstract.d.ts +4 -4
  40. package/SessionManager/SessionManagerAbstract.d.ts +1 -1
  41. package/Task/GitTask.d.ts +1 -1
  42. package/Task/GitTask.js +2 -2
  43. package/Task/MariadbTask.d.ts +1 -1
  44. package/Task/MariadbTask.js +1 -1
  45. package/Task/MssqlTask.d.ts +1 -1
  46. package/Task/MysqlDumpTask.d.ts +1 -1
  47. package/Task/PostgresqlDumpTask.d.ts +1 -1
  48. package/Task/ScriptTask.d.ts +5 -5
  49. package/Task/ScriptTask.js +6 -6
  50. package/Task/SqlDumpTaskAbstract.d.ts +2 -2
  51. package/Task/SqlDumpTaskAbstract.js +2 -2
  52. package/Task/TaskAbstract.d.ts +4 -2
  53. package/Task/TaskAbstract.js +7 -0
  54. package/package.json +8 -8
  55. package/util/DataFormat.d.ts +1 -1
  56. package/util/ObjectVault.d.ts +1 -1
  57. package/util/ResticUtil.d.ts +3 -2
  58. package/util/ResticUtil.js +12 -10
  59. package/util/cli-util.d.ts +1 -1
  60. package/util/datatruck/config-util.d.ts +9 -9
  61. package/util/date-util.d.ts +1 -1
  62. package/util/fs-util.d.ts +4 -1
  63. package/util/fs-util.js +21 -3
  64. package/util/object-util.d.ts +1 -1
  65. package/util/process-util.d.ts +3 -3
  66. package/util/progress.d.ts +2 -2
  67. package/util/string-util.d.ts +1 -1
  68. package/util/zip-util.d.ts +3 -3
  69. package/util/zip-util.js +18 -16
@@ -1,12 +1,12 @@
1
1
  import type { ConfigType } from "../Config/Config";
2
2
  import { PackageConfigType } from "../Config/PackageConfig";
3
3
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
4
- import { TaskConfigType } from "../Config/TaskConfig";
5
4
  import { AppError } from "../Error/AppError";
6
5
  import { SnapshotType } from "../Repository/RepositoryAbstract";
7
6
  import { BackupSessionManager } from "../SessionManager/BackupSessionManager";
7
+ import { TaskAbstract } from "../Task/TaskAbstract";
8
8
  import { IfRequireKeys } from "../util/ts-util";
9
- export declare type BackupActionOptionsType = {
9
+ export type BackupActionOptionsType = {
10
10
  repositoryNames?: string[];
11
11
  repositoryTypes?: string[];
12
12
  packageNames?: string[];
@@ -23,10 +23,26 @@ export declare class BackupAction<TRequired extends boolean = true> {
23
23
  protected repoErrors: Record<string, Error[]>;
24
24
  constructor(config: ConfigType, options?: IfRequireKeys<TRequired, BackupActionOptionsType>);
25
25
  protected init(session: BackupSessionManager): Promise<[SnapshotType, PackageConfigType[]]>;
26
- protected execTask(session: BackupSessionManager, pkg: PackageConfigType, task: TaskConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
27
- protected execRepository(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
28
- protected execCopyRepository(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, mirrorRepo: RepositoryConfigType, snapshot: SnapshotType): Promise<boolean>;
26
+ protected task(session: BackupSessionManager, pkg: PackageConfigType, task: TaskAbstract<any>, snapshot: SnapshotType, targetPath: string | undefined): Promise<{
27
+ error: boolean;
28
+ tmpDirs: string[];
29
+ }>;
30
+ protected backup(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<{
31
+ error: boolean;
32
+ tmpDirs: string[];
33
+ }>;
34
+ protected copyBackup(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, mirrorRepo: RepositoryConfigType, snapshot: SnapshotType): Promise<{
35
+ error: boolean;
36
+ tmpDirs: string[];
37
+ }>;
29
38
  protected getError(pkg: PackageConfigType): AppError | null;
39
+ protected splitRepositories(repositoryNames: string[]): {
40
+ repoNames: string[];
41
+ mirrors: {
42
+ sourceName: string;
43
+ name: string;
44
+ }[];
45
+ };
30
46
  exec(session: BackupSessionManager): Promise<{
31
47
  total: number;
32
48
  errors: number;
@@ -5,6 +5,7 @@ const AppError_1 = require("../Error/AppError");
5
5
  const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
6
6
  const TaskFactory_1 = require("../Factory/TaskFactory");
7
7
  const config_util_1 = require("../util/datatruck/config-util");
8
+ const fs_util_1 = require("../util/fs-util");
8
9
  const crypto_1 = require("crypto");
9
10
  class BackupAction {
10
11
  constructor(config, options = {}) {
@@ -53,10 +54,10 @@ class BackupAction {
53
54
  }
54
55
  return [snapshot, packages];
55
56
  }
56
- async execTask(session, pkg, task, snapshot, targetPath) {
57
+ async task(session, pkg, task, snapshot, targetPath) {
57
58
  const taskId = session.findTaskId({
58
59
  packageName: pkg.name,
59
- taskName: task.name,
60
+ taskName: pkg.task.name,
60
61
  });
61
62
  await session.startTask({
62
63
  id: taskId,
@@ -68,8 +69,7 @@ class BackupAction {
68
69
  }
69
70
  else {
70
71
  try {
71
- const taskInstance = (0, TaskFactory_1.TaskFactory)(task);
72
- await taskInstance.onBackup({
72
+ await task.onBackup({
73
73
  package: pkg,
74
74
  options: this.options,
75
75
  snapshot,
@@ -92,9 +92,12 @@ class BackupAction {
92
92
  id: taskId,
93
93
  error: error?.stack,
94
94
  });
95
- return error ? false : true;
95
+ return {
96
+ error: error ? false : true,
97
+ tmpDirs: task.tmpDirs,
98
+ };
96
99
  }
97
- async execRepository(session, pkg, repo, snapshot, targetPath) {
100
+ async backup(session, pkg, repo, snapshot, targetPath) {
98
101
  const repositoryId = session.findRepositoryId({
99
102
  packageName: pkg.name,
100
103
  repositoryName: repo.name,
@@ -103,12 +106,13 @@ class BackupAction {
103
106
  id: repositoryId,
104
107
  });
105
108
  let error;
109
+ let repoInstance;
106
110
  if (this.taskErrors[pkg.name]?.length) {
107
111
  error = new AppError_1.AppError("Task failed");
108
112
  }
109
113
  else {
110
114
  try {
111
- const repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
115
+ repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
112
116
  await repoInstance.onBackup({
113
117
  package: pkg,
114
118
  targetPath,
@@ -134,9 +138,12 @@ class BackupAction {
134
138
  id: repositoryId,
135
139
  error: error?.stack,
136
140
  });
137
- return error ? false : true;
141
+ return {
142
+ error: error ? false : true,
143
+ tmpDirs: repoInstance?.tmpDirs ?? [],
144
+ };
138
145
  }
139
- async execCopyRepository(session, pkg, repo, mirrorRepo, snapshot) {
146
+ async copyBackup(session, pkg, repo, mirrorRepo, snapshot) {
140
147
  const repositoryId = session.findRepositoryId({
141
148
  packageName: pkg.name,
142
149
  repositoryName: mirrorRepo.name,
@@ -145,12 +152,13 @@ class BackupAction {
145
152
  id: repositoryId,
146
153
  });
147
154
  let error;
155
+ let repoInstance;
148
156
  if (this.taskErrors[pkg.name]?.length) {
149
157
  error = new AppError_1.AppError("Task failed");
150
158
  }
151
159
  else {
152
160
  try {
153
- const repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
161
+ repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
154
162
  await repoInstance.onCopyBackup({
155
163
  options: this.options,
156
164
  package: pkg,
@@ -174,7 +182,10 @@ class BackupAction {
174
182
  id: repositoryId,
175
183
  error: error?.stack,
176
184
  });
177
- return error ? false : true;
185
+ return {
186
+ error: error ? false : true,
187
+ tmpDirs: repoInstance?.tmpDirs ?? [],
188
+ };
178
189
  }
179
190
  getError(pkg) {
180
191
  const taskErrors = this.taskErrors[pkg.name]?.length;
@@ -192,12 +203,33 @@ class BackupAction {
192
203
  return null;
193
204
  }
194
205
  }
206
+ splitRepositories(repositoryNames) {
207
+ const mirrorRepoMap = {};
208
+ const allMirrorRepoNames = [];
209
+ const repoNames = repositoryNames ?? [];
210
+ for (const repoName of repoNames) {
211
+ const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
212
+ if (repo.mirrorRepoNames)
213
+ mirrorRepoMap[repoName] = repo.mirrorRepoNames.filter((mirrorRepoName) => {
214
+ allMirrorRepoNames.push(mirrorRepoName);
215
+ return repoNames.includes(mirrorRepoName);
216
+ });
217
+ }
218
+ return {
219
+ repoNames: repoNames.filter((v) => !allMirrorRepoNames.includes(v)),
220
+ mirrors: repoNames.flatMap((sourceName) => {
221
+ const mirrorNames = mirrorRepoMap[sourceName] || [];
222
+ return mirrorNames.map((name) => ({
223
+ sourceName,
224
+ name,
225
+ }));
226
+ }),
227
+ };
228
+ }
195
229
  async exec(session) {
196
230
  const [snapshot, packages] = await this.init(session);
197
- let total = 0;
198
231
  let errors = 0;
199
232
  for (const pkg of packages) {
200
- total++;
201
233
  const id = session.findId({
202
234
  packageName: pkg.name,
203
235
  });
@@ -205,6 +237,7 @@ class BackupAction {
205
237
  id,
206
238
  });
207
239
  let targetPath;
240
+ let taskTmpDirs = [];
208
241
  if (pkg.task) {
209
242
  const taskInstance = (0, TaskFactory_1.TaskFactory)(pkg.task);
210
243
  const result = await taskInstance.onBeforeBackup({
@@ -212,35 +245,29 @@ class BackupAction {
212
245
  package: pkg,
213
246
  snapshot,
214
247
  });
215
- await this.execTask(session, pkg, pkg.task, snapshot, (targetPath = result?.targetPath));
216
- }
217
- const mirrorRepoMap = {};
218
- const allMirrorRepoNames = [];
219
- const repoNames = pkg.repositoryNames ?? [];
220
- for (const repoName of repoNames) {
221
- const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
222
- if (repo.mirrorRepoNames)
223
- mirrorRepoMap[repoName] = repo.mirrorRepoNames.filter((mirrorRepoName) => {
224
- allMirrorRepoNames.push(mirrorRepoName);
225
- return repoNames.includes(mirrorRepoName);
226
- });
248
+ const taskResult = await this.task(session, pkg, taskInstance, snapshot, (targetPath = result?.targetPath));
249
+ taskTmpDirs.push(...taskResult.tmpDirs);
227
250
  }
251
+ const { repoNames, mirrors } = this.splitRepositories(pkg.repositoryNames ?? []);
228
252
  for (const repoName of repoNames) {
229
- if (allMirrorRepoNames.includes(repoName))
230
- continue;
231
253
  const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
232
- await this.execRepository(session, pkg, repo, snapshot, targetPath);
254
+ const { tmpDirs } = await this.backup(session, pkg, repo, snapshot, targetPath);
255
+ if (!this.options.verbose)
256
+ await (0, fs_util_1.rmTmpDir)(tmpDirs);
233
257
  }
234
- for (const repoName of repoNames) {
235
- const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
236
- const mirrorRepoNames = mirrorRepoMap[repoName];
237
- if (mirrorRepoNames) {
238
- for (const mirrorRepoName of mirrorRepoNames) {
239
- const mirrorRepo = (0, config_util_1.findRepositoryOrFail)(this.config, mirrorRepoName);
240
- await this.execCopyRepository(session, pkg, repo, mirrorRepo, snapshot);
241
- }
258
+ if (!this.options.verbose) {
259
+ await (0, fs_util_1.rmTmpDir)(taskTmpDirs);
260
+ if (pkg.path && (0, fs_util_1.isTmpDir)(pkg.path)) {
261
+ await (0, fs_util_1.rmTmpDir)(pkg.path);
242
262
  }
243
263
  }
264
+ for (const mirror of mirrors) {
265
+ const repo = (0, config_util_1.findRepositoryOrFail)(this.config, mirror.sourceName);
266
+ const mirrorRepo = (0, config_util_1.findRepositoryOrFail)(this.config, mirror.name);
267
+ const { tmpDirs } = await this.copyBackup(session, pkg, repo, mirrorRepo, snapshot);
268
+ if (!this.options.verbose)
269
+ await (0, fs_util_1.rmTmpDir)(tmpDirs);
270
+ }
244
271
  const error = this.getError(pkg);
245
272
  if (error)
246
273
  errors++;
@@ -253,7 +280,7 @@ class BackupAction {
253
280
  snapshotId: snapshot.id.slice(0, 8),
254
281
  });
255
282
  return {
256
- total: total,
283
+ total: packages.length,
257
284
  errors: errors,
258
285
  };
259
286
  }
@@ -2,7 +2,7 @@ import type { ConfigType } from "../Config/Config";
2
2
  import { ReadDataType } from "../SessionDriver/SessionDriverAbstract";
3
3
  import { BackupSessionManager } from "../SessionManager/BackupSessionManager";
4
4
  import { IfRequireKeys } from "../util/ts-util";
5
- export declare type BackupSessionsActionOptionsType = ReadDataType & {
5
+ export type BackupSessionsActionOptionsType = ReadDataType & {
6
6
  verbose?: boolean;
7
7
  };
8
8
  export declare class BackupSessionsAction<TRequired extends boolean = true> {
@@ -1,5 +1,5 @@
1
1
  import { IfRequireKeys } from "../util/ts-util";
2
- export declare type CleanCacheActionOptionsType = {
2
+ export type CleanCacheActionOptionsType = {
3
3
  verbose?: boolean;
4
4
  };
5
5
  export declare class CleanCacheAction<TRequired extends boolean = true> {
@@ -1,7 +1,7 @@
1
1
  import { GlobalOptionsType } from "../Command/CommandAbstract";
2
2
  import type { ConfigType } from "../Config/Config";
3
3
  import { IfRequireKeys } from "../util/ts-util";
4
- export declare type ConfigActionOptionsType = {
4
+ export type ConfigActionOptionsType = {
5
5
  path: string;
6
6
  verbose?: boolean;
7
7
  };
@@ -1,6 +1,6 @@
1
1
  import type { ConfigType } from "../Config/Config";
2
2
  import { IfRequireKeys } from "../util/ts-util";
3
- export declare type InitActionOptionsType = {
3
+ export type InitActionOptionsType = {
4
4
  repositoryNames?: string[];
5
5
  repositoryTypes?: string[];
6
6
  verbose?: boolean;
@@ -2,7 +2,7 @@ import type { ConfigType } from "../Config/Config";
2
2
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
3
3
  import { IfRequireKeys } from "../util/ts-util";
4
4
  import { SnapshotExtendedType, SnapshotsActionOptionsType } from "./SnapshotsAction";
5
- export declare type PruneActionsOptionsType = {
5
+ export type PruneActionsOptionsType = {
6
6
  ids?: string[];
7
7
  packageNames?: string[];
8
8
  repositoryNames?: string[];
@@ -21,7 +21,7 @@ export declare type PruneActionsOptionsType = {
21
21
  longId?: boolean;
22
22
  returnsAll?: boolean;
23
23
  };
24
- export declare type PruneResultType = {
24
+ export type PruneResultType = {
25
25
  total: number;
26
26
  prune: number;
27
27
  snapshots: (SnapshotExtendedType & {
@@ -1,12 +1,12 @@
1
1
  import type { ConfigType } from "../Config/Config";
2
2
  import { PackageConfigType } from "../Config/PackageConfig";
3
3
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
4
- import { TaskConfigType } from "../Config/TaskConfig";
5
4
  import { AppError } from "../Error/AppError";
6
5
  import { SnapshotResultType } from "../Repository/RepositoryAbstract";
7
6
  import { RestoreSessionManager } from "../SessionManager/RestoreSessionManager";
7
+ import { TaskAbstract } from "../Task/TaskAbstract";
8
8
  import { IfRequireKeys } from "../util/ts-util";
9
- export declare type RestoreActionOptionsType = {
9
+ export type RestoreActionOptionsType = {
10
10
  snapshotId: string;
11
11
  tags?: string[];
12
12
  packageNames?: string[];
@@ -16,10 +16,10 @@ export declare type RestoreActionOptionsType = {
16
16
  repositoryTypes?: string[];
17
17
  verbose?: boolean;
18
18
  };
19
- declare type SnapshotType = SnapshotResultType & {
19
+ type SnapshotType = SnapshotResultType & {
20
20
  repositoryName: string;
21
21
  };
22
- declare type SnapshotAndConfigType = [SnapshotType, PackageConfigType | null];
22
+ type SnapshotAndConfigType = [SnapshotType, PackageConfigType | null];
23
23
  export declare class RestoreAction<TRequired extends boolean = true> {
24
24
  readonly config: ConfigType;
25
25
  readonly options: IfRequireKeys<TRequired, RestoreActionOptionsType>;
@@ -30,8 +30,14 @@ export declare class RestoreAction<TRequired extends boolean = true> {
30
30
  protected init(session: RestoreSessionManager, snapshotId: string, snapshots: SnapshotAndConfigType[]): Promise<void>;
31
31
  protected findSnapshots(): Promise<SnapshotType[]>;
32
32
  protected groupSnapshots(snapshots: SnapshotType[]): SnapshotType[];
33
- protected execTask(session: RestoreSessionManager, pkg: PackageConfigType, task: TaskConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
34
- protected execRepository(session: RestoreSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
33
+ protected task(session: RestoreSessionManager, pkg: PackageConfigType, task: TaskAbstract<any>, snapshot: SnapshotType, targetPath: string | undefined): Promise<{
34
+ error: boolean;
35
+ tmpDirs: string[];
36
+ }>;
37
+ protected restore(session: RestoreSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<{
38
+ error: boolean;
39
+ tmpDirs: string[];
40
+ }>;
35
41
  protected getError(pkg: PackageConfigType): AppError | null;
36
42
  exec(session: RestoreSessionManager): Promise<boolean>;
37
43
  }
@@ -88,10 +88,10 @@ class RestoreAction {
88
88
  return true;
89
89
  });
90
90
  }
91
- async execTask(session, pkg, task, snapshot, targetPath) {
91
+ async task(session, pkg, task, snapshot, targetPath) {
92
92
  const taskId = session.findTaskId({
93
93
  packageName: pkg.name,
94
- taskName: task.name,
94
+ taskName: pkg.task.name,
95
95
  });
96
96
  await session.startTask({
97
97
  id: taskId,
@@ -105,8 +105,7 @@ class RestoreAction {
105
105
  }
106
106
  else {
107
107
  try {
108
- const taskInstance = (0, TaskFactory_1.TaskFactory)(task);
109
- await taskInstance.onRestore({
108
+ await task.onRestore({
110
109
  package: pkg,
111
110
  options: this.options,
112
111
  snapshot,
@@ -129,9 +128,12 @@ class RestoreAction {
129
128
  id: taskId,
130
129
  error: error?.stack,
131
130
  });
132
- return error ? false : true;
131
+ return {
132
+ error: error ? false : true,
133
+ tmpDirs: task?.tmpDirs ?? [],
134
+ };
133
135
  }
134
- async execRepository(session, pkg, repo, snapshot, targetPath) {
136
+ async restore(session, pkg, repo, snapshot, targetPath) {
135
137
  const repositoryId = session.findRepositoryId({
136
138
  packageName: pkg.name,
137
139
  repositoryName: repo.name,
@@ -140,6 +142,7 @@ class RestoreAction {
140
142
  id: repositoryId,
141
143
  });
142
144
  let repoError;
145
+ let repoInstance;
143
146
  try {
144
147
  if (typeof pkg.restorePath !== "string")
145
148
  throw new AppError_1.AppError("Restore path is not defined");
@@ -148,7 +151,7 @@ class RestoreAction {
148
151
  throw new AppError_1.AppError(`Restore path is not empty: ${pkg.restorePath}`);
149
152
  if (this.options.verbose)
150
153
  (0, cli_util_1.logExec)(`restorePath=${pkg.restorePath}`);
151
- const repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
154
+ repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
152
155
  await repoInstance.onRestore({
153
156
  package: pkg,
154
157
  targetPath,
@@ -179,7 +182,10 @@ class RestoreAction {
179
182
  id: repositoryId,
180
183
  error: repoError?.stack,
181
184
  });
182
- return repoError ? false : true;
185
+ return {
186
+ error: repoError ? false : true,
187
+ tmpDirs: repoInstance?.tmpDirs || [],
188
+ };
183
189
  }
184
190
  getError(pkg) {
185
191
  const taskErrors = this.taskErrors[pkg.name]?.length;
@@ -223,8 +229,9 @@ class RestoreAction {
223
229
  });
224
230
  await session.start({ id });
225
231
  let targetPath;
232
+ let taskInstance;
226
233
  if (pkg.task) {
227
- const taskInstance = (0, TaskFactory_1.TaskFactory)(pkg.task);
234
+ taskInstance = (0, TaskFactory_1.TaskFactory)(pkg.task);
228
235
  const result = await taskInstance.onBeforeRestore({
229
236
  options: this.options,
230
237
  package: pkg,
@@ -232,9 +239,16 @@ class RestoreAction {
232
239
  });
233
240
  targetPath = result?.targetPath;
234
241
  }
235
- await this.execRepository(session, pkg, repo, snapshot, targetPath);
236
- if (pkg.task)
237
- await this.execTask(session, pkg, pkg.task, snapshot, targetPath);
242
+ const { tmpDirs } = await this.restore(session, pkg, repo, snapshot, targetPath);
243
+ if (taskInstance) {
244
+ await this.task(session, pkg, taskInstance, snapshot, targetPath);
245
+ }
246
+ if (!this.options.verbose) {
247
+ await (0, fs_util_1.rmTmpDir)(taskInstance?.tmpDirs || []);
248
+ await (0, fs_util_1.rmTmpDir)(tmpDirs);
249
+ if (pkg.restorePath && (0, fs_util_1.isTmpDir)(pkg.restorePath))
250
+ await (0, fs_util_1.rmTmpDir)(pkg.restorePath);
251
+ }
238
252
  const error = this.getError(pkg);
239
253
  await session.end({
240
254
  id,
@@ -2,7 +2,7 @@ import type { ConfigType } from "../Config/Config";
2
2
  import { ReadDataType } from "../SessionDriver/SessionDriverAbstract";
3
3
  import { RestoreSessionManager } from "../SessionManager/RestoreSessionManager";
4
4
  import { IfRequireKeys } from "../util/ts-util";
5
- export declare type RestoreSessionsActionOptionsType = ReadDataType & {
5
+ export type RestoreSessionsActionOptionsType = ReadDataType & {
6
6
  verbose?: boolean;
7
7
  };
8
8
  export declare class RestoreSessionsAction<TRequired extends boolean = true> {
@@ -2,8 +2,8 @@ import type { ConfigType } from "../Config/Config";
2
2
  import { RepositoryConfigEnabledActionType } from "../Config/RepositoryConfig";
3
3
  import { SnapshotResultType } from "../Repository/RepositoryAbstract";
4
4
  import { IfRequireKeys } from "../util/ts-util";
5
- export declare type SnapshotGroupByType = keyof Pick<SnapshotExtendedType, "packageName" | "repositoryName" | "repositoryType">;
6
- export declare type SnapshotsActionOptionsType = {
5
+ export type SnapshotGroupByType = keyof Pick<SnapshotExtendedType, "packageName" | "repositoryName" | "repositoryType">;
6
+ export type SnapshotsActionOptionsType = {
7
7
  ids?: string[];
8
8
  repositoryNames?: string[];
9
9
  packageNames?: string[];
@@ -21,7 +21,7 @@ export declare type SnapshotsActionOptionsType = {
21
21
  lastYearly?: number;
22
22
  groupBy?: SnapshotGroupByType[];
23
23
  };
24
- export declare type SnapshotExtendedType = {
24
+ export type SnapshotExtendedType = {
25
25
  shortId: string;
26
26
  repositoryName: string;
27
27
  repositoryType: string;
@@ -1,7 +1,7 @@
1
1
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
2
2
  import { If } from "../util/ts-util";
3
3
  import { CommandAbstract } from "./CommandAbstract";
4
- export declare type BackupCommandOptionsType<TResolved = false> = {
4
+ export type BackupCommandOptionsType<TResolved = false> = {
5
5
  package?: If<TResolved, string[]>;
6
6
  packageTask?: If<TResolved, string[]>;
7
7
  repository?: If<TResolved, string[]>;
@@ -1,6 +1,6 @@
1
1
  import { If } from "../util/ts-util";
2
2
  import { CommandAbstract } from "./CommandAbstract";
3
- export declare type BackupSessionsCommandOptionsType<TResolved = false> = {
3
+ export type BackupSessionsCommandOptionsType<TResolved = false> = {
4
4
  package?: If<TResolved, string[]>;
5
5
  repository?: If<TResolved, string[]>;
6
6
  tag?: If<TResolved, string[]>;
@@ -1,5 +1,5 @@
1
1
  import { CommandAbstract } from "./CommandAbstract";
2
- export declare type CleanCacheCommandOptionsType<TResolved = false> = {};
2
+ export type CleanCacheCommandOptionsType<TResolved = false> = {};
3
3
  export declare class CleanCacheCommand extends CommandAbstract<CleanCacheCommandOptionsType<false>, CleanCacheCommandOptionsType<true>> {
4
4
  onOptions(): import("../util/cli-util").OptionsType<CleanCacheCommandOptionsType<false>, CleanCacheCommandOptionsType<true>>;
5
5
  onExec(): Promise<number>;
@@ -2,14 +2,14 @@ import { ConfigType } from "../Config/Config";
2
2
  import { FormatType } from "../util/DataFormat";
3
3
  import { OptionsType } from "../util/cli-util";
4
4
  import { SimilarObject } from "../util/ts-util";
5
- export declare type GlobalOptionsType<TResolved = false> = {
5
+ export type GlobalOptionsType<TResolved = false> = {
6
6
  config: string | ConfigType;
7
7
  outputFormat?: FormatType;
8
8
  verbose?: number;
9
9
  progress?: "auto" | "plain" | "tty";
10
10
  progressInterval?: number;
11
11
  };
12
- export declare type CommandConstructorType<TUnresolvedOptions, TOptions extends SimilarObject<TUnresolvedOptions>> = {
12
+ export type CommandConstructorType<TUnresolvedOptions, TOptions extends SimilarObject<TUnresolvedOptions>> = {
13
13
  new (globalOptions: GlobalOptionsType<true>, options: TOptions): CommandAbstract<TUnresolvedOptions, TOptions>;
14
14
  };
15
15
  export declare abstract class CommandAbstract<TUnresolvedOptions, TOptions extends SimilarObject<TUnresolvedOptions>> {
@@ -1,13 +1,13 @@
1
1
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
2
2
  import { If } from "../util/ts-util";
3
3
  import { CommandAbstract } from "./CommandAbstract";
4
- export declare type ConfigCommandOptionsType<TResolved = false> = {
4
+ export type ConfigCommandOptionsType<TResolved = false> = {
5
5
  package?: If<TResolved, string[]>;
6
6
  packageTask?: If<TResolved, string[]>;
7
7
  repository?: If<TResolved, string[]>;
8
8
  repositoryType?: If<TResolved, RepositoryConfigType["type"][]>;
9
9
  };
10
- export declare type ConfigCommandLogType = {
10
+ export type ConfigCommandLogType = {
11
11
  packageName: string;
12
12
  repositoryNames: string[];
13
13
  taskName: string | undefined;
@@ -2,11 +2,11 @@ import { InitAction } from "../Action/InitAction";
2
2
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
3
3
  import { If, Unwrap } from "../util/ts-util";
4
4
  import { CommandAbstract } from "./CommandAbstract";
5
- export declare type InitCommandOptionsType<TResolved = false> = {
5
+ export type InitCommandOptionsType<TResolved = false> = {
6
6
  repository?: If<TResolved, string[]>;
7
7
  repositoryType?: If<TResolved, RepositoryConfigType["type"][]>;
8
8
  };
9
- export declare type InitCommandLogType = Unwrap<InitAction["exec"]>;
9
+ export type InitCommandLogType = Unwrap<InitAction["exec"]>;
10
10
  export declare class InitCommand extends CommandAbstract<InitCommandOptionsType<false>, InitCommandOptionsType<true>> {
11
11
  onOptions(): import("../util/cli-util").OptionsType<InitCommandOptionsType<false>, InitCommandOptionsType<true>>;
12
12
  onExec(): Promise<number>;
@@ -2,7 +2,7 @@ import { SnapshotGroupByType } from "../Action/SnapshotsAction";
2
2
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
3
3
  import { If } from "../util/ts-util";
4
4
  import { CommandAbstract } from "./CommandAbstract";
5
- export declare type PruneCommandOptionsType<TResolved = false> = {
5
+ export type PruneCommandOptionsType<TResolved = false> = {
6
6
  id?: If<TResolved, string[]>;
7
7
  longId?: boolean;
8
8
  package?: If<TResolved, string[]>;
@@ -1,7 +1,7 @@
1
1
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
2
2
  import { If } from "../util/ts-util";
3
3
  import { CommandAbstract } from "./CommandAbstract";
4
- export declare type RestoreCommandOptionsType<TResolved = false> = {
4
+ export type RestoreCommandOptionsType<TResolved = false> = {
5
5
  id: string;
6
6
  package?: If<TResolved, string[]>;
7
7
  packageTask?: If<TResolved, string[]>;
@@ -1,6 +1,6 @@
1
1
  import { If } from "../util/ts-util";
2
2
  import { CommandAbstract } from "./CommandAbstract";
3
- export declare type RestoreSessionsCommandOptionsType<TResolved = false> = {
3
+ export type RestoreSessionsCommandOptionsType<TResolved = false> = {
4
4
  package?: If<TResolved, string[]>;
5
5
  repository?: If<TResolved, string[]>;
6
6
  tag?: If<TResolved, string[]>;
@@ -2,7 +2,7 @@ import { SnapshotsAction } from "../Action/SnapshotsAction";
2
2
  import { RepositoryConfigType } from "../Config/RepositoryConfig";
3
3
  import { If, Unwrap } from "../util/ts-util";
4
4
  import { CommandAbstract } from "./CommandAbstract";
5
- export declare type SnapshotsCommandOptionsType<TResolved = false> = {
5
+ export type SnapshotsCommandOptionsType<TResolved = false> = {
6
6
  id?: If<TResolved, string[]>;
7
7
  package?: If<TResolved, string[]>;
8
8
  packageTask?: If<TResolved, string[]>;
@@ -20,7 +20,7 @@ export declare type SnapshotsCommandOptionsType<TResolved = false> = {
20
20
  groupBy?: If<TResolved, SnapshotsAction["options"]["groupBy"]>;
21
21
  tag?: If<TResolved, string[]>;
22
22
  };
23
- export declare type SnapshotsCommandLogType = Unwrap<SnapshotsAction["exec"]>;
23
+ export type SnapshotsCommandLogType = Unwrap<SnapshotsAction["exec"]>;
24
24
  export declare class SnapshotsCommand extends CommandAbstract<SnapshotsCommandOptionsType<false>, SnapshotsCommandOptionsType<true>> {
25
25
  onOptions(): import("../util/cli-util").OptionsType<SnapshotsCommandOptionsType<false>, SnapshotsCommandOptionsType<true>>;
26
26
  onExec(): Promise<number>;
@@ -1,7 +1,7 @@
1
1
  import { PackageConfigType } from "./PackageConfig";
2
2
  import { RepositoryConfigType } from "./RepositoryConfig";
3
3
  import type { JSONSchema7 } from "json-schema";
4
- export declare type ConfigType = {
4
+ export type ConfigType = {
5
5
  tempDir?: string;
6
6
  repositories: RepositoryConfigType[];
7
7
  packages: PackageConfigType[];
@@ -4,12 +4,12 @@ import type { TaskConfigType } from "./TaskConfig";
4
4
  import { JSONSchema7 } from "json-schema";
5
5
  export declare const packageConfigDefinition: JSONSchema7;
6
6
  export declare const pathsObjectDefinition: JSONSchema7;
7
- export declare type PathsObjectType = {
7
+ export type PathsObjectType = {
8
8
  type: "spawn";
9
9
  command: string;
10
10
  args?: string[];
11
11
  };
12
- export declare type PackageConfigType = {
12
+ export type PackageConfigType = {
13
13
  name: string;
14
14
  enabled?: boolean;
15
15
  task?: TaskConfigType;
@@ -3,7 +3,7 @@ import { GitPackageRepositoryConfigType, gitRepositoryName } from "../Repository
3
3
  import { ResticPackageRepositoryConfigType, resticRepositoryName } from "../Repository/ResticRepository";
4
4
  import type { JSONSchema7 } from "json-schema";
5
5
  export declare const packageRepositoryConfigDefinition: JSONSchema7;
6
- export declare type PackageRepositoryConfigType = {
6
+ export type PackageRepositoryConfigType = {
7
7
  names?: string[];
8
8
  } & ({
9
9
  type: typeof resticRepositoryName;
@@ -1,4 +1,4 @@
1
1
  import { PruneActionsOptionsType } from "../Action/PruneAction";
2
2
  import { JSONSchema7 } from "json-schema";
3
3
  export declare const prunePolicyConfigDefinition: JSONSchema7;
4
- export declare type PrunePolicyConfigType = Pick<PruneActionsOptionsType, "keepDaily" | "keepHourly" | "keepMinutely" | "keepLast" | "keepMonthly" | "keepWeekly" | "keepYearly" | "groupBy" | "tags">;
4
+ export type PrunePolicyConfigType = Pick<PruneActionsOptionsType, "keepDaily" | "keepHourly" | "keepMinutely" | "keepLast" | "keepMonthly" | "keepWeekly" | "keepYearly" | "groupBy" | "tags">;