@synopackageland/cli 0.48.15 → 0.48.16

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.48.16
4
+
5
+ - install and deploy repair a broken package at its installed version with an in-place reinstall that keeps App data; healthy packages at the same version stay unchanged
6
+ - status shows broken packages with the exact repair command
7
+
3
8
  ## 0.48.15
4
9
 
5
10
  - Accept identity_gateway.secure_context: required; check and build reject it when the pinned SDK does not support it, and the gateway shows a localized HTTPS guidance page for HTTP visits without redirecting
package/README.md CHANGED
@@ -520,6 +520,13 @@ and daemon cause/endpoint when DSM provides them. Configure a reachable mirror,
520
520
  trust an inspecting CA in Container Manager, or use `images pin` and preload the
521
521
  pinned image. Pinning alone does not download layers onto the NAS. Pull tasks
522
522
  are not cancelled or replayed when their response is lost or a budget expires.
523
+ Installing the same release of a healthy package is a no-op. For a broken package,
524
+ `install <package-id>@<installed-version> --yes` or `install <file.spk> --yes`
525
+ reports `action: "repair"` and uses DSM's in-place reinstall with the existing data;
526
+ it never uninstalls first. Completion requires the selected version, a running
527
+ payload and no broken/error state. `status <package-id>` includes the failure
528
+ and a pinned repair command. An unresolved repair retains its operation record;
529
+ check DSM Package Center before retrying, since uncertain writes are not replayed.
523
530
  Broken packages skip stop during uninstall; their existing install error does not
524
531
  block removal, while new uninstall errors still fail clearly.
525
532
  Uninstall resumes a stopped or stopping package, waits for an existing uninstall,
@@ -40,6 +40,7 @@ export declare function fetchInstalledPackageState(dsmOrigin: string, cookieHead
40
40
  signal?: AbortSignal;
41
41
  ignoreOperation?: boolean;
42
42
  }): Promise<InstalledPackageState | undefined>;
43
+ export declare function packageIsBroken(state: InstalledPackageState): boolean;
43
44
  export interface InstallWaitOptions {
44
45
  packageId: string;
45
46
  expectedVersion?: string;
@@ -47,6 +48,8 @@ export interface InstallWaitOptions {
47
48
  pollMs?: number;
48
49
  requireRunning?: boolean;
49
50
  requireTransition?: boolean;
51
+ /** The old corrupt payload can remain visible until DSM replaces it. */
52
+ repairing?: boolean;
50
53
  onProgress?: (message: string) => void;
51
54
  maxPolls?: number;
52
55
  consumePoll?: () => void;
@@ -78,6 +81,7 @@ export interface LocalSpkInstallOptions {
78
81
  spkPath: string;
79
82
  version: string;
80
83
  profileName?: string;
84
+ repair?: boolean;
81
85
  extraValues?: Record<string, string>;
82
86
  deadlineMs?: number;
83
87
  pollMs?: number;
@@ -161,7 +161,7 @@ export async function fetchInstalledPackageState(dsmOrigin, cookieHeader, packag
161
161
  state.installed = true;
162
162
  }
163
163
  }
164
- if (operation && !state.state && !(state.installed && packageFailure(state))) {
164
+ if (operation && !state.state && !(state.installed && packageIsBroken(state))) {
165
165
  const task = await dsmWebApi(dsmOrigin, cookieHeader, {
166
166
  api: 'SYNO.Core.Package.Installation', method: 'status', version: '1', task_id: jsonApiParam(operation.taskId),
167
167
  }, { timeoutMs, signal: context.signal, allowFailure: true });
@@ -196,7 +196,7 @@ function installStatusIsBroken(status) {
196
196
  }
197
197
  return /(broken|error|fail|150)/i.test(status);
198
198
  }
199
- function packageFailure(state) {
199
+ export function packageIsBroken(state) {
200
200
  return installStatusIsBroken(state.status) || state.statusCode === 150 ||
201
201
  Boolean(state.statusCode && /broken|error|fail|corruption/i.test(state.statusDescription ?? '')) ||
202
202
  Boolean(state.error && (state.error.code !== undefined ? state.error.code !== 0 : state.error.description));
@@ -219,6 +219,7 @@ export async function waitForInstalledVersion(readState, options) {
219
219
  const pollMs = options.pollMs ?? dsmPollIntervalMs();
220
220
  const progress = progressReporter(options.onProgress);
221
221
  let transitioned = !options.requireTransition;
222
+ let repairStarted = !options.repairing;
222
223
  while (Date.now() < deadline) {
223
224
  consumePoll();
224
225
  let state;
@@ -231,7 +232,9 @@ export async function waitForInstalledVersion(readState, options) {
231
232
  throw error;
232
233
  timedOut = true;
233
234
  }
234
- if (state && !installInProgress(state) && packageFailure(state)) {
235
+ if (state && (installInProgress(state) || !packageIsBroken(state)))
236
+ repairStarted = true;
237
+ if (state && repairStarted && !installInProgress(state) && packageIsBroken(state)) {
235
238
  throw new CtlError('DSM_INSTALL_FAILED', `DSM reports package ${options.packageId} install did not complete (Package Center status ${state.status ?? 'unknown'}): ${failureDetail(state)}`.trim(), 'Check the DSM Package Center install/start log');
236
239
  }
237
240
  const running = /^(run|running)$/i.test(state?.status ?? '');
@@ -240,7 +243,7 @@ export async function waitForInstalledVersion(readState, options) {
240
243
  transitioned = true;
241
244
  if (Date.now() >= deadline)
242
245
  break;
243
- if (state?.installed && !/installing|upgrading|starting/i.test(state.status ?? '') &&
246
+ if (state?.installed && !packageIsBroken(state) && !/installing|upgrading|starting/i.test(state.status ?? '') &&
244
247
  (!options.expectedVersion || state.version === options.expectedVersion) &&
245
248
  (!options.requireRunning || running) && transitioned)
246
249
  return state;
@@ -292,7 +295,7 @@ export async function uninstallPackageFromDsm(options) {
292
295
  if (state && Date.now() < deadline) {
293
296
  if (done(state))
294
297
  return state;
295
- if (packageFailure(state) && !(phase === 'uninstalling' && previousFailure === failureDetail(state)))
298
+ if (packageIsBroken(state) && !(phase === 'uninstalling' && previousFailure === failureDetail(state)))
296
299
  throw new CtlError('DSM_UNINSTALL_FAILED', `DSM reports ${options.packageId} failed while ${phase}: ${failureDetail(state) || state.status}`, 'Check the DSM Package Center stop/uninstall log');
297
300
  }
298
301
  progress(timedOut ? `${options.packageId}: status request timed out; ${phase}…` :
@@ -331,7 +334,7 @@ export async function uninstallPackageFromDsm(options) {
331
334
  throw new CtlError('PACKAGE_BUSY', `Package ${options.packageId} has an unresolved operation`, 'Wait for DSM to finish before uninstalling');
332
335
  if (before.installed === false)
333
336
  return;
334
- const broken = packageFailure(before) && !installInProgress(before);
337
+ const broken = packageIsBroken(before) && !installInProgress(before);
335
338
  if (broken) {
336
339
  previousFailure = failureDetail(before);
337
340
  progress(`${options.packageId}: broken package (${previousFailure || before.status}); uninstalling directly without stop…`);
@@ -490,7 +493,8 @@ export async function installPackageFromLocalSpk(options) {
490
493
  await installDelay(Math.min(pollMs, remaining(requestMs)), signal);
491
494
  }
492
495
  }
493
- if (before.state || before.installed === null)
496
+ if (before.state || before.installed === null ||
497
+ (options.repair && readPackageOperation(options.dsmOrigin, options.packageId)))
494
498
  throw new CtlError('PACKAGE_BUSY', `Package ${options.packageId} already has an unresolved operation`, 'Check package status before installing again');
495
499
  if (options.containerImages?.length) {
496
500
  phase = 'pulling container images';
@@ -508,7 +512,7 @@ export async function installPackageFromLocalSpk(options) {
508
512
  progress(`${options.packageId}: uploading…`);
509
513
  const uploaded = await cancelableInstall(() => uploadLocalSpk(options, sid, remaining(operationMs)), signal);
510
514
  const compound = JSON.stringify(catalogCompoundSteps(uploaded, { version: options.version, size: readFileSync(options.spkPath).byteLength }, { blupgrade: before.installed, extraValues: options.extraValues }));
511
- phase = before.installed ? 'upgrading' : 'installing';
515
+ phase = options.repair ? 'repairing' : before.installed ? 'upgrading' : 'installing';
512
516
  operation = savePackageOperation(options.dsmOrigin, options.packageId, { taskId: uploaded.taskId,
513
517
  operation: before.installed ? 'upgrading' : 'installing', fromVersion: before.installed ? before.version : undefined, toVersion: options.version });
514
518
  progress(`${options.packageId}: ${phase}…`);
@@ -529,7 +533,8 @@ export async function installPackageFromLocalSpk(options) {
529
533
  const completed = await waitForInstalledVersion(budget => fetchInstalledPackageState(options.dsmOrigin, options.cookieHeader, options.packageId, Math.min(requestMs, budget), { signal, ignoreOperation: true }), { packageId: options.packageId, expectedVersion: options.version,
530
534
  deadlineMs: Number.isFinite(deadline) ? remaining(Number.MAX_SAFE_INTEGER) : undefined, pollMs, requireRunning: true, consumePoll, signal,
531
535
  // A lost same-version reinstall reply must not accept the old running instance.
532
- requireTransition: timedOut && before.installed === true && before.version === options.version,
536
+ requireTransition: timedOut && !packageIsBroken(before) && before.installed === true && before.version === options.version,
537
+ repairing: options.repair && packageIsBroken(before),
533
538
  onProgress: progress });
534
539
  verified = true;
535
540
  progress(`${options.packageId}: ${phase} complete (${completed.version}, DSM status ${completed.status})`);
@@ -1,3 +1,4 @@
1
+ import { type InstalledPackageState } from "./catalog-install.js";
1
2
  export interface NasTarget {
2
3
  arch: string;
3
4
  version: string;
@@ -28,5 +29,5 @@ export interface Dependency {
28
29
  }
29
30
  export declare function dependencies(value: unknown): Dependency[];
30
31
  export declare function satisfies(version: string, dependency: Dependency): boolean;
31
- export declare function resolveInstallPlan(root: StoreEntry, entries: StoreEntry[], target: NasTarget, installed: Map<string, string>): StoreEntry[];
32
+ export declare function resolveInstallPlan(root: StoreEntry, entries: StoreEntry[], target: NasTarget, installed: ReadonlyMap<string, string | InstalledPackageState>): StoreEntry[];
32
33
  export declare function verifyPins(bytes: Buffer, entry: Pick<StoreEntry, "size" | "md5" | "sha256">): void;
@@ -1,3 +1,4 @@
1
+ import { packageIsBroken } from "./catalog-install.js";
1
2
  import { createHash } from "node:crypto";
2
3
  import { CtlError } from "../ctl/errors.js";
3
4
  import { familyOfArchToken } from "../build-spk/dsm-arch.js";
@@ -127,9 +128,15 @@ export function resolveInstallPlan(root, entries, target, installed) {
127
128
  throw fail("PACKAGE_DEPENDENCY_CONFLICT", `Conflicting dependency ${dep.id}`);
128
129
  continue;
129
130
  }
130
- if (installed.has(dep.id) && satisfies(installed.get(dep.id), dep))
131
+ const current = installed.get(dep.id);
132
+ const currentVersion = typeof current === "string" ? current : current?.version;
133
+ if (typeof current === "object" && (current.state || current.installed === null))
134
+ throw fail("PACKAGE_BUSY", `Dependency ${dep.id} already has an unresolved operation`);
135
+ if (currentVersion && satisfies(currentVersion, dep) &&
136
+ (typeof current === "string" || !packageIsBroken(current)))
131
137
  continue;
132
- const candidates = entries.filter((e) => e.package === dep.id && satisfies(e.version, dep));
138
+ const candidates = entries.filter((e) => e.package === dep.id && satisfies(e.version, dep) &&
139
+ (!(typeof current === "object" && packageIsBroken(current) && currentVersion && satisfies(currentVersion, dep)) || e.version === currentVersion));
133
140
  if (!candidates.length)
134
141
  throw fail("PACKAGE_DEPENDENCY_REQUIRED", `Install required Synology package ${dep.id}${Object.entries(dep.constraints)
135
142
  .map(([k, v]) => k + v)
@@ -1,4 +1,5 @@
1
1
  import { type NasConnection } from "./connection.js";
2
+ import { type InstalledPackageState } from "./catalog-install.js";
2
3
  import { type NasTarget, type StoreEntry } from "./install-plan.js";
3
4
  export declare const DEFAULT_PACKAGE_SOURCE = "https://packages.synopkgland.com";
4
5
  export declare function packageId(value: string): string;
@@ -18,6 +19,7 @@ export declare function installPackage(spec: string, options?: InstallOptions, c
18
19
  source: string;
19
20
  packages: {
20
21
  signed?: boolean | undefined;
22
+ status?: string | undefined;
21
23
  package: string;
22
24
  version: string;
23
25
  size: number;
@@ -31,6 +33,7 @@ export declare function installPackage(spec: string, options?: InstallOptions, c
31
33
  source: string;
32
34
  packages: {
33
35
  signed?: boolean | undefined;
36
+ status?: string | undefined;
34
37
  package: string;
35
38
  version: string;
36
39
  size: number;
@@ -39,13 +42,14 @@ export declare function installPackage(spec: string, options?: InstallOptions, c
39
42
  parameters: string[];
40
43
  dryRun: boolean;
41
44
  } | {
42
- status: import("./catalog-install.js").InstalledPackageState | undefined;
45
+ status: InstalledPackageState | undefined;
43
46
  message?: string | undefined;
44
47
  host: string;
45
48
  target: NasTarget;
46
49
  source: string;
47
50
  packages: {
48
51
  signed?: boolean | undefined;
52
+ status?: string | undefined;
49
53
  package: string;
50
54
  version: string;
51
55
  size: number;
@@ -69,7 +73,10 @@ export declare function uninstallPackage(id: string, options?: {
69
73
  package: string;
70
74
  action: string;
71
75
  }>;
72
- export declare function packageStatus(id: string, host?: string): Promise<{
76
+ export declare function packageStatus(id: string, host?: string, connection?: NasConnection): Promise<{
77
+ recommendedCommand?: string | undefined;
78
+ message?: string | undefined;
79
+ broken: boolean;
73
80
  installed: boolean | null;
74
81
  state?: "installing" | "upgrading" | "starting" | "stopping" | "uninstalling" | "unknown";
75
82
  fromVersion?: string;
@@ -7,7 +7,7 @@ import { inspectAnySpk } from "../spk/inspect.js";
7
7
  import { containerImageReferences } from './container-pull.js';
8
8
  import { connectNas, requireAdministrator, } from "./connection.js";
9
9
  import { fetchPackageSource } from "../package-source.js";
10
- import { fetchInstalledPackageState, installPackageFromLocalSpk, uninstallPackageFromDsm, } from "./catalog-install.js";
10
+ import { fetchInstalledPackageState, packageStateFromRecord, packageIsBroken, installPackageFromLocalSpk, uninstallPackageFromDsm, } from "./catalog-install.js";
11
11
  import { assertCompatible, sourceUrl, selectEntry, resolveInstallPlan, verifyPins, compareVersions, } from "./install-plan.js";
12
12
  export const DEFAULT_PACKAGE_SOURCE = "https://packages.synopkgland.com";
13
13
  const fail = (code, message, hint = "Check Package Center and retry") => new CtlError(code, message, hint, 3);
@@ -49,13 +49,13 @@ export async function readFeed(source, target) {
49
49
  }
50
50
  async function inventory(nas) {
51
51
  const data = await nas.call("SYNO.Core.Package", "list", 2, {
52
- additional: '["status"]',
52
+ additional: '["status","installed_info"]',
53
53
  ignore_hidden: "false",
54
54
  });
55
55
  if (!Array.isArray(data?.packages) ||
56
56
  (data.total !== undefined && data.total !== data.packages.length))
57
57
  throw fail("NAS_INVENTORY_INVALID", "Installed package inventory is incomplete");
58
- return new Map(data.packages.map((p) => [p.id, p.version]));
58
+ return new Map(data.packages.map((p) => [p.id, packageStateFromRecord(p)]));
59
59
  }
60
60
  async function confirm(action, yes) {
61
61
  if (yes)
@@ -118,12 +118,24 @@ export async function installPackage(spec, options = {}, connection) {
118
118
  root = selectEntry(entries, packageId(match[1]), match[2], target);
119
119
  }
120
120
  const plan = resolveInstallPlan(root, entries, target, installed);
121
- for (const item of plan)
122
- if (installed.has(item.package) &&
123
- compareVersions(item.version, installed.get(item.package)) < 0)
121
+ for (const item of plan) {
122
+ const state = installed.get(item.package);
123
+ if (state?.state || state?.installed === null)
124
+ throw fail("PACKAGE_BUSY", `Package ${item.package} already has an unresolved operation`, "Check package status before installing again");
125
+ if (state && !state.version)
126
+ throw fail("NAS_INVENTORY_INVALID", `DSM did not report the installed version of ${item.package}`);
127
+ if (state && compareVersions(item.version, state.version) < 0)
124
128
  throw fail("PACKAGE_DOWNGRADE_REFUSED", `Refusing downgrade of ${item.package}`, "Choose the installed version or a newer release");
125
- const changes = plan.filter((item) => !installed.has(item.package) ||
126
- compareVersions(item.version, installed.get(item.package)) !== 0);
129
+ }
130
+ const actionFor = (item) => {
131
+ const state = installed.get(item.package);
132
+ if (!state)
133
+ return "install";
134
+ if (compareVersions(item.version, state.version) !== 0)
135
+ return "upgrade";
136
+ return packageIsBroken(state) ? "repair" : "none";
137
+ };
138
+ const changes = plan.filter((item) => actionFor(item) !== "none");
127
139
  const publicPlan = {
128
140
  host: nas.name,
129
141
  target,
@@ -132,11 +144,9 @@ export async function installPackage(spec, options = {}, connection) {
132
144
  package: item.package,
133
145
  version: item.version,
134
146
  size: item.size,
135
- action: !installed.has(item.package)
136
- ? "install"
137
- : compareVersions(item.version, installed.get(item.package)) === 0
138
- ? "none"
139
- : "upgrade",
147
+ action: actionFor(item),
148
+ ...(installed.get(item.package)?.status
149
+ ? { status: installed.get(item.package).status } : {}),
140
150
  ...(item.package === root.package && report
141
151
  ? { signed: report.signed }
142
152
  : {}),
@@ -151,7 +161,7 @@ export async function installPackage(spec, options = {}, connection) {
151
161
  if (!changes.length)
152
162
  return publicPlan;
153
163
  await requireAdministrator(nas);
154
- await confirm(`Install ${changes.map((e) => e.package + "@" + e.version).join(", ")}`, options.yes);
164
+ await confirm(changes.map((e) => `${actionFor(e)} ${e.package}@${e.version}`).join(", "), options.yes);
155
165
  // Download, verify and inspect the entire plan before the first NAS write.
156
166
  const files = new Map();
157
167
  const images = new Map();
@@ -182,6 +192,7 @@ export async function installPackage(spec, options = {}, connection) {
182
192
  packageId: entry.package,
183
193
  version: entry.version,
184
194
  spkPath: files.get(entry.package),
195
+ repair: actionFor(entry) === "repair",
185
196
  containerImages: images.get(entry.package),
186
197
  extraValues: entry.package === root.package ? options.param : undefined,
187
198
  });
@@ -219,11 +230,18 @@ export async function uninstallPackage(id, options = {}) {
219
230
  });
220
231
  return { host: nas.name, package: id, installed: false };
221
232
  }
222
- export async function packageStatus(id, host) {
233
+ export async function packageStatus(id, host, connection) {
223
234
  packageId(id);
224
- const nas = await connectNas(host);
235
+ const nas = connection ?? await connectNas(host);
225
236
  const state = await fetchInstalledPackageState(nas.session.origin, nas.session.cookie, id);
226
237
  if (!state)
227
238
  throw fail("PACKAGE_STATUS_UNKNOWN", "DSM did not return a verifiable package state");
228
- return { host: nas.name, package: id, ...state };
239
+ const broken = packageIsBroken(state);
240
+ const quotedHost = "'" + nas.name.replace(/'/g, "'\\''") + "'";
241
+ return { host: nas.name, package: id, ...state, broken,
242
+ ...(broken && state.version && /^[0-9][0-9._-]*$/.test(state.version) && !state.state ? {
243
+ recommendedCommand: `synopkgland install ${id}@${state.version}${nas.name === "env" ? "" : ` --host ${quotedHost}`} --yes`,
244
+ message: "Package is broken; reinstall the same release to repair it while retaining data",
245
+ } : {}),
246
+ };
229
247
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synopackageland/cli",
3
- "version": "0.48.15",
3
+ "version": "0.48.16",
4
4
  "description": "Syno Package Land Developer Kit CLI",
5
5
  "type": "module",
6
6
  "bin": {