@nsyan/ssh 0.1.0 → 0.1.1
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/index.ts +68 -41
- package/package.json +1 -1
- package/src/core/deploy.ts +12 -6
- package/src/core/doctor.ts +37 -6
- package/src/core/guard.ts +59 -26
- package/src/core/hash.ts +12 -8
- package/src/runtime.ts +288 -91
- package/src/scan/save.ts +1 -3
- package/src/transports/ftp.ts +6 -1
- package/src/transports/openssh.ts +189 -15
- package/src/transports/ssh2.ts +25 -10
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// transports/openssh.ts —— 调用本机 ssh。继承 ~/.ssh/config、代理跳转和密钥。
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
-
import { chmodSync, mkdirSync } from "node:fs";
|
|
4
|
-
import { homedir } from "node:os";
|
|
3
|
+
import { chmodSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
4
|
+
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { shellQuote, wrapWithWatchdog } from "../core/guard.js";
|
|
7
|
-
import { parseRemoteHash, remoteHashCommand, sha256File } from "../core/hash.js";
|
|
7
|
+
import { clipUtf8, parseRemoteHash, remoteHashCommand, sha256File } from "../core/hash.js";
|
|
8
8
|
import { TransferMismatchError, UnsupportedError, type HostProfile } from "../core/types.js";
|
|
9
9
|
|
|
10
10
|
export function controlPath(): string {
|
|
@@ -14,16 +14,150 @@ export function controlPath(): string {
|
|
|
14
14
|
return join(dir, "%C");
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/** ssh 与 sftp 共用的选项。`-i` 必须在这里,否则 sftp 走不到密钥认证。 */
|
|
17
18
|
function sshOptions(profile: HostProfile): string[] {
|
|
18
19
|
if (profile.auth.kind === "password") {
|
|
19
20
|
throw new UnsupportedError("openssh 传输不接受密码或 MFA。需要密码时改用 ssh2;ProxyJump、证书和 agent 继续走 openssh。");
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
const args = [
|
|
22
23
|
"-o", "BatchMode=yes",
|
|
23
24
|
"-o", "ControlMaster=auto",
|
|
24
25
|
"-o", `ControlPath=${controlPath()}`,
|
|
25
26
|
"-o", "ControlPersist=5m",
|
|
26
27
|
];
|
|
28
|
+
if (profile.auth.privateKeyPath) args.push("-i", profile.auth.privateKeyPath);
|
|
29
|
+
return args;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* sftp / scp 自己不会留下常驻 master(只有 ssh 会),
|
|
34
|
+
* 所以不先把 master 起起来,ControlPath 就是摆设,每次都重新握手。
|
|
35
|
+
* `-O check` 只碰本地 socket,不走网络,比一次握手便宜得多。
|
|
36
|
+
* 起 master 失败不当致命:后续 sftp 会自己握手,并报出自己的错。
|
|
37
|
+
*/
|
|
38
|
+
async function ensureControlMaster(profile: HostProfile): Promise<void> {
|
|
39
|
+
const target = `${profile.user}@${profile.host}`;
|
|
40
|
+
const cp = controlPath();
|
|
41
|
+
const check = await runQuiet("ssh", ["-o", `ControlPath=${cp}`, "-O", "check", target]);
|
|
42
|
+
if (check.code === 0) return;
|
|
43
|
+
const started = await runQuiet("ssh", [
|
|
44
|
+
...sshOptions(profile),
|
|
45
|
+
"-p", String(profile.port ?? 22),
|
|
46
|
+
"-f", "-N", target,
|
|
47
|
+
]);
|
|
48
|
+
if (started.code !== 0) return;
|
|
49
|
+
masters.add(target);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function runQuiet(command: string, args: string[]): Promise<{ code: number | null; stderr: string }> {
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
const child = spawn(command, args, { stdio: ["ignore", "ignore", "pipe"] });
|
|
55
|
+
let stderr = "";
|
|
56
|
+
child.stderr.on("data", (chunk: Buffer) => {
|
|
57
|
+
stderr += chunk.toString("utf8");
|
|
58
|
+
});
|
|
59
|
+
child.on("error", () => resolve({ code: -1, stderr }));
|
|
60
|
+
child.on("close", (code) => resolve({ code, stderr }));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const masters = new Set<string>();
|
|
65
|
+
|
|
66
|
+
/** 会话结束时把后台 master 收掉,不留 5 分钟的孤儿进程。 */
|
|
67
|
+
export async function closeControlMasters(): Promise<void> {
|
|
68
|
+
const targets = [...masters];
|
|
69
|
+
masters.clear();
|
|
70
|
+
await Promise.all(targets.map((target) => runQuiet("ssh", ["-o", `ControlPath=${controlPath()}`, "-O", "exit", target])));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 用 `sftp -b -` 跑一批命令,复用同一条 ControlMaster 连接,不另开握手。
|
|
75
|
+
* 退出码非 0 就报错,不默默返回半个结果。
|
|
76
|
+
*/
|
|
77
|
+
async function sftpBatch(profile: HostProfile, commands: string[]): Promise<string> {
|
|
78
|
+
await ensureControlMaster(profile);
|
|
79
|
+
const args = [...sshOptions(profile), "-P", String(profile.port ?? 22), "-b", "-", `${profile.user}@${profile.host}`];
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const child = spawn("sftp", args, { stdio: ["pipe", "pipe", "pipe"] });
|
|
82
|
+
let stdout = "";
|
|
83
|
+
let stderr = "";
|
|
84
|
+
child.stdin.end(`${commands.join("\n")}\n`);
|
|
85
|
+
child.stdout.on("data", (chunk: Buffer) => {
|
|
86
|
+
stdout += chunk.toString("utf8");
|
|
87
|
+
});
|
|
88
|
+
child.stderr.on("data", (chunk: Buffer) => {
|
|
89
|
+
stderr += chunk.toString("utf8");
|
|
90
|
+
});
|
|
91
|
+
child.on("error", reject);
|
|
92
|
+
child.on("close", (code) => {
|
|
93
|
+
if (code === 0) resolve(stdout);
|
|
94
|
+
else reject(new Error(stderr.trim() || `sftp 退出码 ${code}`));
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 解 `sftp` 的 `ls -l` 输出。longname 是 SFTP 协议给的,不是 shell 的 ls:
|
|
101
|
+
* 首列是权限串,第 5 列是字节数,名字从第 9 列起(名字里可以有空格)。
|
|
102
|
+
*/
|
|
103
|
+
export function parseSftpLongNames(output: string): Array<{ name: string; size: number; directory: boolean }> {
|
|
104
|
+
return output
|
|
105
|
+
.split("\n")
|
|
106
|
+
.map((line) => line.trim())
|
|
107
|
+
.filter((line) => /^[-dlbcps][rwxstT-]{9}/.test(line))
|
|
108
|
+
.map((line) => {
|
|
109
|
+
const fields = line.split(/\s+/);
|
|
110
|
+
return {
|
|
111
|
+
name: fields.slice(8).join(" "),
|
|
112
|
+
size: Number(fields[4]) || 0,
|
|
113
|
+
directory: line.startsWith("d"),
|
|
114
|
+
};
|
|
115
|
+
})
|
|
116
|
+
.filter((entry) => entry.name !== "" && entry.name !== "." && entry.name !== "..");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function listOpenSsh(profile: HostProfile, remotePath: string): Promise<Array<{ name: string; size: number; directory: boolean }>> {
|
|
120
|
+
const out = await sftpBatch(profile, [`ls -l ${shellQuote(remotePath)}`]);
|
|
121
|
+
return parseSftpLongNames(out);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 不解析远端文本:get 到本地临时文件,再按行切。 */
|
|
125
|
+
export async function readOpenSsh(profile: HostProfile, remotePath: string, offset = 1, limit = 200): Promise<string> {
|
|
126
|
+
const tmp = join(tmpdir(), `pi-ssh-read-${process.pid}-${Date.now()}`);
|
|
127
|
+
try {
|
|
128
|
+
await sftpBatch(profile, [`get ${shellQuote(remotePath)} ${shellQuote(tmp)}`]);
|
|
129
|
+
const whole = readFileSync(tmp, "utf8");
|
|
130
|
+
const maxBytes = 512 * 1024;
|
|
131
|
+
const picked: string[] = [];
|
|
132
|
+
let seen = 0;
|
|
133
|
+
let bytes = 0;
|
|
134
|
+
for (const line of whole.split("\n")) {
|
|
135
|
+
seen += 1;
|
|
136
|
+
if (seen < offset || picked.length >= limit) continue;
|
|
137
|
+
const room = maxBytes - bytes;
|
|
138
|
+
if (room <= 0) break;
|
|
139
|
+
const clipped = clipUtf8(line, room);
|
|
140
|
+
picked.push(clipped);
|
|
141
|
+
bytes += Buffer.byteLength(clipped) + 1;
|
|
142
|
+
if (clipped !== line) break;
|
|
143
|
+
}
|
|
144
|
+
return picked.join("\n");
|
|
145
|
+
} finally {
|
|
146
|
+
rmSync(tmp, { force: true });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* OpenSSH 对老服务器会打一串 post-quantum 警告。它是 ssh 自己的提示,
|
|
152
|
+
* 不是命令的输出;合进结果里会让「退出码 0」看起来像出错。
|
|
153
|
+
*/
|
|
154
|
+
export function stripSshNoise(text: string): string {
|
|
155
|
+
return text
|
|
156
|
+
.split(/\r?\n/)
|
|
157
|
+
.filter((line) => !/WARNING: connection is not using a post-quantum key exchange algorithm/.test(line))
|
|
158
|
+
.filter((line) => !/This session may be vulnerable to "store now, decrypt later" attacks/.test(line))
|
|
159
|
+
.filter((line) => !/The server may need to be upgraded\. See https:\/\/openssh\.com\/pq\.html/.test(line))
|
|
160
|
+
.join("\n");
|
|
27
161
|
}
|
|
28
162
|
|
|
29
163
|
export interface OpenSshRequest {
|
|
@@ -31,6 +165,7 @@ export interface OpenSshRequest {
|
|
|
31
165
|
cwd?: string;
|
|
32
166
|
timeoutMs?: number;
|
|
33
167
|
signal?: AbortSignal;
|
|
168
|
+
onData?: (chunk: string) => void;
|
|
34
169
|
}
|
|
35
170
|
|
|
36
171
|
export function execOpenSsh(profile: HostProfile, request: OpenSshRequest): Promise<{ stdout: string; stderr: string; exitCode: number | null; durationMs: number }> {
|
|
@@ -40,11 +175,13 @@ export function execOpenSsh(profile: HostProfile, request: OpenSshRequest): Prom
|
|
|
40
175
|
"-o", "ServerAliveInterval=30",
|
|
41
176
|
"-p", String(profile.port ?? 22),
|
|
42
177
|
];
|
|
43
|
-
if (profile.auth.privateKeyPath) args.push("-i", profile.auth.privateKeyPath);
|
|
44
178
|
args.push("-l", profile.user, profile.host, wrapWithWatchdog(remote));
|
|
45
179
|
const started = Date.now();
|
|
46
180
|
return new Promise((resolve, reject) => {
|
|
47
|
-
|
|
181
|
+
// stdin 必须是 pipe 且不能 end():watchdog 脚本靠 `exec 3<&0` 拿一条通道,
|
|
182
|
+
// 通道 EOF 就当作「客户端放弃」立即 kill 命令。stdio 用 "ignore" 时 fd 0 是
|
|
183
|
+
// /dev/null,fd 3 立刻 EOF,命令会被自己的 watcher 秒杀(exit 143 + 空输出)。
|
|
184
|
+
const child = spawn("ssh", args, { stdio: ["pipe", "pipe", "pipe"] });
|
|
48
185
|
let stdout = "";
|
|
49
186
|
let stderr = "";
|
|
50
187
|
const timer = request.timeoutMs
|
|
@@ -53,7 +190,9 @@ export function execOpenSsh(profile: HostProfile, request: OpenSshRequest): Prom
|
|
|
53
190
|
const abort = () => child.kill("SIGTERM");
|
|
54
191
|
request.signal?.addEventListener("abort", abort, { once: true });
|
|
55
192
|
child.stdout.on("data", (chunk: Buffer) => {
|
|
56
|
-
|
|
193
|
+
const text = chunk.toString("utf8");
|
|
194
|
+
stdout += text;
|
|
195
|
+
request.onData?.(text);
|
|
57
196
|
});
|
|
58
197
|
child.stderr.on("data", (chunk: Buffer) => {
|
|
59
198
|
stderr += chunk.toString("utf8");
|
|
@@ -65,7 +204,7 @@ export function execOpenSsh(profile: HostProfile, request: OpenSshRequest): Prom
|
|
|
65
204
|
child.on("close", (code) => {
|
|
66
205
|
clearTimeout(timer);
|
|
67
206
|
request.signal?.removeEventListener("abort", abort);
|
|
68
|
-
resolve({ stdout, stderr, exitCode: code, durationMs: Date.now() - started });
|
|
207
|
+
resolve({ stdout, stderr: stripSshNoise(stderr), exitCode: code, durationMs: Date.now() - started });
|
|
69
208
|
});
|
|
70
209
|
});
|
|
71
210
|
}
|
|
@@ -73,11 +212,11 @@ export function execOpenSsh(profile: HostProfile, request: OpenSshRequest): Prom
|
|
|
73
212
|
export function copyOpenSsh(profile: HostProfile, direction: "put" | "get", localPath: string, remotePath: string): Promise<void> {
|
|
74
213
|
const remote = `${profile.user}@${profile.host}:${remotePath}`;
|
|
75
214
|
const args = ["-P", String(profile.port ?? 22), ...sshOptions(profile)];
|
|
76
|
-
if (profile.auth.privateKeyPath) args.push("-i", profile.auth.privateKeyPath);
|
|
77
215
|
if (direction === "put") args.push(localPath, remote);
|
|
78
216
|
else args.push(remote, localPath);
|
|
79
|
-
return new Promise((resolve, reject) => {
|
|
80
|
-
|
|
217
|
+
return ensureControlMaster(profile).then(() => new Promise<void>((resolve, reject) => {
|
|
218
|
+
// 同上:scp 也走同一套 ControlMaster,stdin 必须保持 pipe。
|
|
219
|
+
const child = spawn("scp", args, { stdio: ["pipe", "pipe", "pipe"] });
|
|
81
220
|
let stderr = "";
|
|
82
221
|
child.stderr.on("data", (chunk: Buffer) => {
|
|
83
222
|
stderr += chunk.toString("utf8");
|
|
@@ -87,10 +226,40 @@ export function copyOpenSsh(profile: HostProfile, direction: "put" | "get", loca
|
|
|
87
226
|
if (code === 0) resolve();
|
|
88
227
|
else reject(new Error(stderr.trim() || `scp 退出码 ${code}`));
|
|
89
228
|
});
|
|
90
|
-
});
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* scp 直接传到目标路径并做双端 sha256 校验,不额外加 `.part` 后缀。
|
|
234
|
+
* 部署场景自己就把目标定成了 `<releaseDir>.part`,这里再加一层会变成 `.part.part`。
|
|
235
|
+
*/
|
|
236
|
+
export async function scpPutVerified(profile: HostProfile, localPath: string, remotePath: string, signal?: AbortSignal): Promise<{ bytes: number; sha256: string }> {
|
|
237
|
+
const local = await sha256File(localPath);
|
|
238
|
+
await copyOpenSsh(profile, "put", localPath, remotePath);
|
|
239
|
+
const checked = await execOpenSsh(profile, { command: remoteHashCommand(remotePath), signal });
|
|
240
|
+
const remote = parseRemoteHash(checked.stdout);
|
|
241
|
+
if (checked.exitCode !== 0 || remote !== local.hash) {
|
|
242
|
+
throw new TransferMismatchError(`sha256 不一致:本地 ${local.hash},远端 ${remote ?? "无"}。${remotePath} 保留,原文件未动`);
|
|
243
|
+
}
|
|
244
|
+
return { bytes: local.bytes, sha256: local.hash };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* scp 下载后做双端 sha256 比对。scp 退出码 0 不代表内容完整,
|
|
249
|
+
* 传输中断、磁盘满、服务端限流都可能静默截断。
|
|
250
|
+
*/
|
|
251
|
+
export async function getOpenSsh(profile: HostProfile, remotePath: string, localPath: string): Promise<{ bytes: number; sha256: string }> {
|
|
252
|
+
await copyOpenSsh(profile, "get", localPath, remotePath);
|
|
253
|
+
const local = await sha256File(localPath);
|
|
254
|
+
const checked = await execOpenSsh(profile, { command: remoteHashCommand(remotePath) });
|
|
255
|
+
const remote = parseRemoteHash(checked.stdout);
|
|
256
|
+
if (checked.exitCode !== 0 || remote !== local.hash) {
|
|
257
|
+
throw new TransferMismatchError(`下载后 sha256 不一致:本地 ${local.hash},远端 ${remote ?? "无"}。${localPath} 可能不完整`);
|
|
258
|
+
}
|
|
259
|
+
return { bytes: local.bytes, sha256: local.hash };
|
|
91
260
|
}
|
|
92
261
|
|
|
93
|
-
export async function putOpenSsh(profile: HostProfile, localPath: string, remotePath: string, backupPath?: string): Promise<{ bytes: number; sha256: string; backupPath?: string }> {
|
|
262
|
+
export async function putOpenSsh(profile: HostProfile, localPath: string, remotePath: string, backupPath?: string): Promise<{ bytes: number; sha256: string; backupPath?: string; backupCopied?: boolean }> {
|
|
94
263
|
const local = await sha256File(localPath);
|
|
95
264
|
const part = `${remotePath}.part`;
|
|
96
265
|
await copyOpenSsh(profile, "put", localPath, part);
|
|
@@ -99,11 +268,16 @@ export async function putOpenSsh(profile: HostProfile, localPath: string, remote
|
|
|
99
268
|
if (checked.exitCode !== 0 || remote !== local.hash) {
|
|
100
269
|
throw new TransferMismatchError(`sha256 不一致:本地 ${local.hash},远端 ${remote ?? "无"}。${part} 保留,原文件未动`);
|
|
101
270
|
}
|
|
271
|
+
let backupCopied = false;
|
|
102
272
|
if (backupPath) {
|
|
103
|
-
const
|
|
273
|
+
const source = shellQuote(remotePath);
|
|
274
|
+
const dest = shellQuote(backupPath);
|
|
275
|
+
// rename 只改目录项。跨文件系统时 mv 报 EXDEV,降级为复制。
|
|
276
|
+
const moved = await execOpenSsh(profile, { command: `if [ -e ${source} ]; then mv ${source} ${dest} || { mkdir -p $(dirname ${dest}) && cp -p ${source} ${dest} && rm -f ${source} && echo __COPIED__; }; fi` });
|
|
104
277
|
if (moved.exitCode !== 0) throw new TransferMismatchError(`备份失败:${moved.stderr || moved.stdout}`);
|
|
278
|
+
backupCopied = moved.stdout.includes("__COPIED__");
|
|
105
279
|
}
|
|
106
280
|
const renamed = await execOpenSsh(profile, { command: `mv ${shellQuote(part)} ${shellQuote(remotePath)}` });
|
|
107
281
|
if (renamed.exitCode !== 0) throw new TransferMismatchError(`转正失败:${renamed.stderr || renamed.stdout}`);
|
|
108
|
-
return { bytes: local.bytes, sha256: local.hash, backupPath };
|
|
282
|
+
return { bytes: local.bytes, sha256: local.hash, backupPath, backupCopied };
|
|
109
283
|
}
|
package/src/transports/ssh2.ts
CHANGED
|
@@ -168,6 +168,15 @@ export class Ssh2Pool {
|
|
|
168
168
|
return stored.client;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* 已建立的连接上握手阶段算过的指纹。
|
|
173
|
+
* 连接复用时 `hostVerifier` 不会再被调用,调用方拿不到指纹,
|
|
174
|
+
* 只能从这里取;否则第二次 `ssh_hosts test` 会报一个空指纹。
|
|
175
|
+
*/
|
|
176
|
+
fingerprintOf(profileId: string): string {
|
|
177
|
+
return this.connections.get(profileId)?.fingerprint ?? "";
|
|
178
|
+
}
|
|
179
|
+
|
|
171
180
|
/** 占一个 channel 名额。满 4 个就等。 */
|
|
172
181
|
async acquire(profileId: string): Promise<Lease> {
|
|
173
182
|
const stored = this.connections.get(profileId);
|
|
@@ -437,16 +446,18 @@ export class Ssh2Pool {
|
|
|
437
446
|
let stderr = "";
|
|
438
447
|
let spillPath: string | undefined;
|
|
439
448
|
let finished = false;
|
|
449
|
+
const overBudget = (prospective: number, lines: number) => prospective > 50_000 || lines > 2000;
|
|
440
450
|
const absorb = (which: "out" | "err", chunk: string) => {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
|
|
451
|
+
// 预算看的是「加上本块之后」的总量。只看已累积量的话,
|
|
452
|
+
// 一次到达的 3001 行(~14KB)永远触发不了 2000 行上限。
|
|
453
|
+
const prospective = stdout.length + stderr.length + chunk.length;
|
|
454
|
+
const lines = `${stdout}${chunk}`.split("\n").length + stderr.split("\n").length - 1;
|
|
455
|
+
if (!spillPath && overBudget(prospective, lines)) {
|
|
456
|
+
spillPath = join(tmpdir(), `pi-ssh-${process.pid}-${Date.now()}.log`);
|
|
457
|
+
mkdirSync(tmpdir(), { recursive: true });
|
|
458
|
+
writeFileSync(spillPath, stdout + stderr);
|
|
449
459
|
}
|
|
460
|
+
if (spillPath) appendFileSync(spillPath, chunk);
|
|
450
461
|
if (which === "out") stdout = (stdout + chunk).slice(-50_000);
|
|
451
462
|
else stderr = (stderr + chunk).slice(-50_000);
|
|
452
463
|
};
|
|
@@ -517,10 +528,14 @@ export class Ssh2Pool {
|
|
|
517
528
|
if (!exists) return { copied: false };
|
|
518
529
|
const source = quote(request.remotePath);
|
|
519
530
|
const dest = quote(request.backupPath);
|
|
531
|
+
// 备份可能收进 <root>/.pi-ssh-backup/<相对路径>.<ts>,那个目录还不存在。
|
|
532
|
+
const prepared = await this.execLeased(profileId, `mkdir -p $(dirname ${dest})`);
|
|
533
|
+
if (prepared.exitCode !== 0) {
|
|
534
|
+
throw new TransferMismatchError(`建备份目录失败:${prepared.stderr || prepared.stdout}`);
|
|
535
|
+
}
|
|
520
536
|
const moved = await this.execLeased(profileId, `mv ${source} ${dest}`);
|
|
521
537
|
if (moved.exitCode === 0) return { path: request.backupPath, copied: false };
|
|
522
|
-
const copied = await this.execLeased(profileId, `cp -p ${source} ${dest} && rm -f ${source}`);
|
|
523
|
-
if (copied.exitCode !== 0) {
|
|
538
|
+
const copied = await this.execLeased(profileId, `cp -p ${source} ${dest} && rm -f ${source}`); if (copied.exitCode !== 0) {
|
|
524
539
|
throw new TransferMismatchError(`备份失败:${moved.stderr || copied.stderr || "mv 与 cp 都失败"}`);
|
|
525
540
|
}
|
|
526
541
|
return { path: request.backupPath, copied: true };
|