ssh2-scp 3.3.0 → 3.3.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.
- package/dist/cjs/ssh-fs.cjs +78 -130
- package/dist/esm/ssh-fs.d.ts +2 -1
- package/dist/esm/ssh-fs.js +78 -130
- package/dist/esm/transfer.d.ts +2 -1
- package/package.json +1 -1
package/dist/cjs/ssh-fs.cjs
CHANGED
|
@@ -29,10 +29,6 @@ class SshFs {
|
|
|
29
29
|
maskMode(mode) {
|
|
30
30
|
return mode & 4095;
|
|
31
31
|
}
|
|
32
|
-
getMonthIndex(month) {
|
|
33
|
-
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
34
|
-
return months.indexOf(month);
|
|
35
|
-
}
|
|
36
32
|
runCmd(cmd, timeout = 3e4) {
|
|
37
33
|
return new Promise((resolve, reject) => {
|
|
38
34
|
let timeoutId;
|
|
@@ -144,57 +140,44 @@ class SshFs {
|
|
|
144
140
|
return { size: "0", count: 0 };
|
|
145
141
|
}
|
|
146
142
|
}
|
|
143
|
+
async readListings(remotePath, flags) {
|
|
144
|
+
const operand = remotePath.startsWith("-") ? "./" + remotePath : remotePath;
|
|
145
|
+
const path = "'" + operand.replace(/'/g, "'\\''") + "'";
|
|
146
|
+
const script = [
|
|
147
|
+
'if [ -n "$LC_ALL" ]; then export LC_CTYPE="$LC_ALL"; unset LC_ALL; fi',
|
|
148
|
+
"export LC_TIME=C TZ=UTC0",
|
|
149
|
+
'if ls -d --full-time / >/dev/null 2>&1; then full=--full-time; elif [ "$(ls -dT / 2>/dev/null)" = / ]; then full=-T; else full=; fi',
|
|
150
|
+
// Only the probed option may expand to zero arguments. Always quote the path.
|
|
151
|
+
`ls -${flags} $full "$1" && printf "\\000" && ls -${flags}u $full "$1"`
|
|
152
|
+
].join("; ");
|
|
153
|
+
const output = await this.runCmd(`sh -c '${script}' sh ${path}`);
|
|
154
|
+
const [modified, accessed = ""] = output.split("\0");
|
|
155
|
+
return { entries: parseListing(modified), accessed: parseListing(accessed) };
|
|
156
|
+
}
|
|
147
157
|
async listFiles(remotePath) {
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const type = parts[0].charAt(0);
|
|
157
|
-
let name = parts.slice(8).join(" ");
|
|
158
|
-
if (type === "l") {
|
|
159
|
-
const arrow = name.indexOf(" -> ");
|
|
160
|
-
if (arrow > 0) {
|
|
161
|
-
name = name.slice(0, arrow);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (name === "." || name === "..") continue;
|
|
165
|
-
const mode = parseModeFromLongname(parts[0]);
|
|
166
|
-
const owner = parseInt(parts[2], 10);
|
|
167
|
-
const group = parseInt(parts[3], 10);
|
|
168
|
-
const size = parseInt(parts[4], 10);
|
|
169
|
-
const month = parts[5];
|
|
170
|
-
const day = parts[6];
|
|
171
|
-
const timeOrYear = parts[7];
|
|
172
|
-
let mtime = 0;
|
|
173
|
-
const now = /* @__PURE__ */ new Date();
|
|
174
|
-
const year = now.getFullYear();
|
|
175
|
-
if (timeOrYear.includes(":")) {
|
|
176
|
-
const [hour, minute] = timeOrYear.split(":").map(Number);
|
|
177
|
-
mtime = new Date(year, this.getMonthIndex(month), parseInt(day, 10), hour, minute).getTime();
|
|
178
|
-
} else {
|
|
179
|
-
mtime = new Date(parseInt(timeOrYear, 10), this.getMonthIndex(month), parseInt(day, 10)).getTime();
|
|
180
|
-
}
|
|
181
|
-
result.push({
|
|
158
|
+
const { entries, accessed } = await this.readListings(remotePath, "lan");
|
|
159
|
+
const accessTimes = new Map(accessed.map((entry) => [entry.name, entry.timestamp]));
|
|
160
|
+
return entries.flatMap(({ permissions, uid, gid, size, name, timestamp }) => {
|
|
161
|
+
const type = permissions[0];
|
|
162
|
+
const accessTime = accessTimes.get(name) ?? NaN;
|
|
163
|
+
if (type === "l") name = name.split(" -> ")[0];
|
|
164
|
+
if (name === "." || name === "..") return [];
|
|
165
|
+
return [{
|
|
182
166
|
type,
|
|
183
167
|
name,
|
|
184
168
|
size,
|
|
185
|
-
modifyTime:
|
|
186
|
-
accessTime
|
|
187
|
-
mode,
|
|
169
|
+
modifyTime: timestamp,
|
|
170
|
+
accessTime,
|
|
171
|
+
mode: parseModeFromLongname(permissions),
|
|
188
172
|
rights: {
|
|
189
|
-
user:
|
|
190
|
-
group:
|
|
191
|
-
other:
|
|
173
|
+
user: permissions.substring(1, 4),
|
|
174
|
+
group: permissions.substring(4, 7),
|
|
175
|
+
other: permissions.substring(7, 10)
|
|
192
176
|
},
|
|
193
|
-
owner,
|
|
194
|
-
group
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return result;
|
|
177
|
+
owner: uid,
|
|
178
|
+
group: gid
|
|
179
|
+
}];
|
|
180
|
+
});
|
|
198
181
|
}
|
|
199
182
|
list(remotePath) {
|
|
200
183
|
return this.listFiles(remotePath);
|
|
@@ -203,96 +186,37 @@ class SshFs {
|
|
|
203
186
|
const cmd = options.mode ? `mkdir -m ${this.maskMode(options.mode).toString(8)} -p "${remotePath}"` : `mkdir -p "${remotePath}"`;
|
|
204
187
|
return this.runCmd(cmd);
|
|
205
188
|
}
|
|
206
|
-
async
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
if (parts.length < 9) {
|
|
211
|
-
return {
|
|
212
|
-
size: 0,
|
|
213
|
-
mode: 0,
|
|
214
|
-
uid: 0,
|
|
215
|
-
gid: 0,
|
|
216
|
-
atime: 0,
|
|
217
|
-
mtime: 0,
|
|
218
|
-
isFile: () => false,
|
|
219
|
-
isDirectory: () => false,
|
|
220
|
-
isSymbolicLink: () => false,
|
|
221
|
-
isBlockDevice: () => false,
|
|
222
|
-
isCharacterDevice: () => false,
|
|
223
|
-
isFIFO: () => false,
|
|
224
|
-
isSocket: () => false
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
const size = parseInt(parts[4], 10);
|
|
228
|
-
const modeStr = parts[0];
|
|
229
|
-
const mode = parseModeFromLongname(modeStr);
|
|
230
|
-
const uid = parseInt(parts[2], 10);
|
|
231
|
-
const gid = parseInt(parts[3], 10);
|
|
189
|
+
async readStats(remotePath, flags) {
|
|
190
|
+
const { entries: [entry], accessed: [access] } = await this.readListings(remotePath, flags);
|
|
191
|
+
if (!entry) throw new Error(`Cannot read file metadata: ${remotePath}`);
|
|
192
|
+
const type = entry.permissions[0];
|
|
232
193
|
return {
|
|
233
|
-
size,
|
|
234
|
-
mode,
|
|
235
|
-
uid,
|
|
236
|
-
gid,
|
|
237
|
-
atime:
|
|
238
|
-
mtime:
|
|
239
|
-
isFile: () =>
|
|
240
|
-
isDirectory: () =>
|
|
241
|
-
isSymbolicLink: () =>
|
|
242
|
-
isBlockDevice: () =>
|
|
243
|
-
isCharacterDevice: () =>
|
|
244
|
-
isFIFO: () =>
|
|
245
|
-
isSocket: () =>
|
|
194
|
+
size: entry.size,
|
|
195
|
+
mode: parseModeFromLongname(entry.permissions),
|
|
196
|
+
uid: entry.uid,
|
|
197
|
+
gid: entry.gid,
|
|
198
|
+
atime: Math.floor(access?.timestamp / 1e3),
|
|
199
|
+
mtime: Math.floor(entry.timestamp / 1e3),
|
|
200
|
+
isFile: () => type === "-",
|
|
201
|
+
isDirectory: () => type === "d",
|
|
202
|
+
isSymbolicLink: () => type === "l",
|
|
203
|
+
isBlockDevice: () => type === "b",
|
|
204
|
+
isCharacterDevice: () => type === "c",
|
|
205
|
+
isFIFO: () => type === "p",
|
|
206
|
+
isSocket: () => type === "s"
|
|
246
207
|
};
|
|
247
208
|
}
|
|
209
|
+
stat(remotePath) {
|
|
210
|
+
return this.readStats(remotePath, "ldnL");
|
|
211
|
+
}
|
|
248
212
|
readlink(remotePath) {
|
|
249
213
|
return this.runCmd(`readlink "${remotePath}"`).then((output) => output.trim());
|
|
250
214
|
}
|
|
251
215
|
realpath(remotePath) {
|
|
252
216
|
return this.runCmd(`readlink -f "${remotePath}"`).then((output) => output.trim()).catch(() => this.runCmd(`cd "${remotePath}" && pwd`).then((output) => output.trim()));
|
|
253
217
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const isSymlink = output.trim().startsWith("l");
|
|
257
|
-
const lsOutput = await this.runCmd(`ls -la "${remotePath}"`);
|
|
258
|
-
const parts = lsOutput.trim().split(/\s+/);
|
|
259
|
-
if (parts.length < 9) {
|
|
260
|
-
return {
|
|
261
|
-
size: 0,
|
|
262
|
-
mode: 0,
|
|
263
|
-
uid: 0,
|
|
264
|
-
gid: 0,
|
|
265
|
-
atime: 0,
|
|
266
|
-
mtime: 0,
|
|
267
|
-
isFile: () => false,
|
|
268
|
-
isDirectory: () => false,
|
|
269
|
-
isSymbolicLink: () => false,
|
|
270
|
-
isBlockDevice: () => false,
|
|
271
|
-
isCharacterDevice: () => false,
|
|
272
|
-
isFIFO: () => false,
|
|
273
|
-
isSocket: () => false
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
const size = parseInt(parts[4], 10);
|
|
277
|
-
const modeStr = parts[0];
|
|
278
|
-
const mode = parseModeFromLongname(modeStr);
|
|
279
|
-
const uid = parseInt(parts[2], 10);
|
|
280
|
-
const gid = parseInt(parts[3], 10);
|
|
281
|
-
return {
|
|
282
|
-
size,
|
|
283
|
-
mode,
|
|
284
|
-
uid,
|
|
285
|
-
gid,
|
|
286
|
-
atime: 0,
|
|
287
|
-
mtime: 0,
|
|
288
|
-
isFile: () => !isSymlink && modeStr.startsWith("-"),
|
|
289
|
-
isDirectory: () => !isSymlink && modeStr.startsWith("d"),
|
|
290
|
-
isSymbolicLink: () => isSymlink,
|
|
291
|
-
isBlockDevice: () => modeStr.startsWith("b"),
|
|
292
|
-
isCharacterDevice: () => modeStr.startsWith("c"),
|
|
293
|
-
isFIFO: () => modeStr.startsWith("p"),
|
|
294
|
-
isSocket: () => modeStr.startsWith("s")
|
|
295
|
-
};
|
|
218
|
+
lstat(remotePath) {
|
|
219
|
+
return this.readStats(remotePath, "ldn");
|
|
296
220
|
}
|
|
297
221
|
chmod(remotePath, mode) {
|
|
298
222
|
return this.runCmd(`chmod ${this.maskMode(mode).toString(8)} "${remotePath}"`);
|
|
@@ -359,6 +283,30 @@ class SshFs {
|
|
|
359
283
|
}
|
|
360
284
|
}
|
|
361
285
|
}
|
|
286
|
+
function parseListing(output) {
|
|
287
|
+
return output.split("\n").flatMap((line) => {
|
|
288
|
+
const fields = /^([bcdlps-]\S*)\s+\d+\s+(\S+)\s+(\S+)\s+(\d+(?:,\s*\d+)?|0x[\da-fA-F]+)\s+(.+)$/.exec(line);
|
|
289
|
+
if (!fields) return [];
|
|
290
|
+
const [, permissions, uid, gid, size, tail] = fields;
|
|
291
|
+
const parsed = parseListingDate(tail);
|
|
292
|
+
if (!parsed) return [];
|
|
293
|
+
return [{ permissions, uid: Number(uid), gid: Number(gid), size: parseInt(size), ...parsed }];
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function parseListingDate(tail) {
|
|
297
|
+
const iso = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)?(?: ([+-]\d{4}))? (.+)$/.exec(tail);
|
|
298
|
+
if (iso) {
|
|
299
|
+
const [, date, time, fraction = "", zone = "Z", name] = iso;
|
|
300
|
+
return { timestamp: Date.parse(date + "T" + time + fraction.slice(0, 4) + zone), name };
|
|
301
|
+
}
|
|
302
|
+
const bsd = /^(\w{3})\s+(\d+) (\d{2}:\d{2}:\d{2}) (\d{4}) (.+)$/.exec(tail);
|
|
303
|
+
if (bsd) {
|
|
304
|
+
const [, month, day, time, year, name] = bsd;
|
|
305
|
+
return { timestamp: Date.parse(`${day} ${month} ${year} ${time} GMT`), name };
|
|
306
|
+
}
|
|
307
|
+
const brief = /^\w{3}\s+\d+\s+(?:\d{2}:\d{2}|\d{4}) (.+)$/.exec(tail);
|
|
308
|
+
return brief ? { timestamp: NaN, name: brief[1] } : void 0;
|
|
309
|
+
}
|
|
362
310
|
function createSshFs(session, options) {
|
|
363
311
|
return new SshFs(session, options);
|
|
364
312
|
}
|
package/dist/esm/ssh-fs.d.ts
CHANGED
|
@@ -35,7 +35,6 @@ export declare class SshFs {
|
|
|
35
35
|
private detectChunkSize;
|
|
36
36
|
private getExecOpts;
|
|
37
37
|
private maskMode;
|
|
38
|
-
private getMonthIndex;
|
|
39
38
|
private runCmd;
|
|
40
39
|
private rmFolderCmd;
|
|
41
40
|
private rmCmd;
|
|
@@ -51,11 +50,13 @@ export declare class SshFs {
|
|
|
51
50
|
size: string;
|
|
52
51
|
count: number;
|
|
53
52
|
}>;
|
|
53
|
+
private readListings;
|
|
54
54
|
private listFiles;
|
|
55
55
|
list(remotePath: string): Promise<FileInfo[]>;
|
|
56
56
|
mkdir(remotePath: string, options?: {
|
|
57
57
|
mode?: number;
|
|
58
58
|
}): Promise<string>;
|
|
59
|
+
private readStats;
|
|
59
60
|
stat(remotePath: string): Promise<Stats>;
|
|
60
61
|
readlink(remotePath: string): Promise<string>;
|
|
61
62
|
realpath(remotePath: string): Promise<string>;
|
package/dist/esm/ssh-fs.js
CHANGED
|
@@ -27,10 +27,6 @@ class SshFs {
|
|
|
27
27
|
maskMode(mode) {
|
|
28
28
|
return mode & 4095;
|
|
29
29
|
}
|
|
30
|
-
getMonthIndex(month) {
|
|
31
|
-
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
32
|
-
return months.indexOf(month);
|
|
33
|
-
}
|
|
34
30
|
runCmd(cmd, timeout = 3e4) {
|
|
35
31
|
return new Promise((resolve, reject) => {
|
|
36
32
|
let timeoutId;
|
|
@@ -142,57 +138,44 @@ class SshFs {
|
|
|
142
138
|
return { size: "0", count: 0 };
|
|
143
139
|
}
|
|
144
140
|
}
|
|
141
|
+
async readListings(remotePath, flags) {
|
|
142
|
+
const operand = remotePath.startsWith("-") ? "./" + remotePath : remotePath;
|
|
143
|
+
const path = "'" + operand.replace(/'/g, "'\\''") + "'";
|
|
144
|
+
const script = [
|
|
145
|
+
'if [ -n "$LC_ALL" ]; then export LC_CTYPE="$LC_ALL"; unset LC_ALL; fi',
|
|
146
|
+
"export LC_TIME=C TZ=UTC0",
|
|
147
|
+
'if ls -d --full-time / >/dev/null 2>&1; then full=--full-time; elif [ "$(ls -dT / 2>/dev/null)" = / ]; then full=-T; else full=; fi',
|
|
148
|
+
// Only the probed option may expand to zero arguments. Always quote the path.
|
|
149
|
+
`ls -${flags} $full "$1" && printf "\\000" && ls -${flags}u $full "$1"`
|
|
150
|
+
].join("; ");
|
|
151
|
+
const output = await this.runCmd(`sh -c '${script}' sh ${path}`);
|
|
152
|
+
const [modified, accessed = ""] = output.split("\0");
|
|
153
|
+
return { entries: parseListing(modified), accessed: parseListing(accessed) };
|
|
154
|
+
}
|
|
145
155
|
async listFiles(remotePath) {
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const type = parts[0].charAt(0);
|
|
155
|
-
let name = parts.slice(8).join(" ");
|
|
156
|
-
if (type === "l") {
|
|
157
|
-
const arrow = name.indexOf(" -> ");
|
|
158
|
-
if (arrow > 0) {
|
|
159
|
-
name = name.slice(0, arrow);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (name === "." || name === "..") continue;
|
|
163
|
-
const mode = parseModeFromLongname(parts[0]);
|
|
164
|
-
const owner = parseInt(parts[2], 10);
|
|
165
|
-
const group = parseInt(parts[3], 10);
|
|
166
|
-
const size = parseInt(parts[4], 10);
|
|
167
|
-
const month = parts[5];
|
|
168
|
-
const day = parts[6];
|
|
169
|
-
const timeOrYear = parts[7];
|
|
170
|
-
let mtime = 0;
|
|
171
|
-
const now = /* @__PURE__ */ new Date();
|
|
172
|
-
const year = now.getFullYear();
|
|
173
|
-
if (timeOrYear.includes(":")) {
|
|
174
|
-
const [hour, minute] = timeOrYear.split(":").map(Number);
|
|
175
|
-
mtime = new Date(year, this.getMonthIndex(month), parseInt(day, 10), hour, minute).getTime();
|
|
176
|
-
} else {
|
|
177
|
-
mtime = new Date(parseInt(timeOrYear, 10), this.getMonthIndex(month), parseInt(day, 10)).getTime();
|
|
178
|
-
}
|
|
179
|
-
result.push({
|
|
156
|
+
const { entries, accessed } = await this.readListings(remotePath, "lan");
|
|
157
|
+
const accessTimes = new Map(accessed.map((entry) => [entry.name, entry.timestamp]));
|
|
158
|
+
return entries.flatMap(({ permissions, uid, gid, size, name, timestamp }) => {
|
|
159
|
+
const type = permissions[0];
|
|
160
|
+
const accessTime = accessTimes.get(name) ?? NaN;
|
|
161
|
+
if (type === "l") name = name.split(" -> ")[0];
|
|
162
|
+
if (name === "." || name === "..") return [];
|
|
163
|
+
return [{
|
|
180
164
|
type,
|
|
181
165
|
name,
|
|
182
166
|
size,
|
|
183
|
-
modifyTime:
|
|
184
|
-
accessTime
|
|
185
|
-
mode,
|
|
167
|
+
modifyTime: timestamp,
|
|
168
|
+
accessTime,
|
|
169
|
+
mode: parseModeFromLongname(permissions),
|
|
186
170
|
rights: {
|
|
187
|
-
user:
|
|
188
|
-
group:
|
|
189
|
-
other:
|
|
171
|
+
user: permissions.substring(1, 4),
|
|
172
|
+
group: permissions.substring(4, 7),
|
|
173
|
+
other: permissions.substring(7, 10)
|
|
190
174
|
},
|
|
191
|
-
owner,
|
|
192
|
-
group
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return result;
|
|
175
|
+
owner: uid,
|
|
176
|
+
group: gid
|
|
177
|
+
}];
|
|
178
|
+
});
|
|
196
179
|
}
|
|
197
180
|
list(remotePath) {
|
|
198
181
|
return this.listFiles(remotePath);
|
|
@@ -201,96 +184,37 @@ class SshFs {
|
|
|
201
184
|
const cmd = options.mode ? `mkdir -m ${this.maskMode(options.mode).toString(8)} -p "${remotePath}"` : `mkdir -p "${remotePath}"`;
|
|
202
185
|
return this.runCmd(cmd);
|
|
203
186
|
}
|
|
204
|
-
async
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
if (parts.length < 9) {
|
|
209
|
-
return {
|
|
210
|
-
size: 0,
|
|
211
|
-
mode: 0,
|
|
212
|
-
uid: 0,
|
|
213
|
-
gid: 0,
|
|
214
|
-
atime: 0,
|
|
215
|
-
mtime: 0,
|
|
216
|
-
isFile: () => false,
|
|
217
|
-
isDirectory: () => false,
|
|
218
|
-
isSymbolicLink: () => false,
|
|
219
|
-
isBlockDevice: () => false,
|
|
220
|
-
isCharacterDevice: () => false,
|
|
221
|
-
isFIFO: () => false,
|
|
222
|
-
isSocket: () => false
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
const size = parseInt(parts[4], 10);
|
|
226
|
-
const modeStr = parts[0];
|
|
227
|
-
const mode = parseModeFromLongname(modeStr);
|
|
228
|
-
const uid = parseInt(parts[2], 10);
|
|
229
|
-
const gid = parseInt(parts[3], 10);
|
|
187
|
+
async readStats(remotePath, flags) {
|
|
188
|
+
const { entries: [entry], accessed: [access] } = await this.readListings(remotePath, flags);
|
|
189
|
+
if (!entry) throw new Error(`Cannot read file metadata: ${remotePath}`);
|
|
190
|
+
const type = entry.permissions[0];
|
|
230
191
|
return {
|
|
231
|
-
size,
|
|
232
|
-
mode,
|
|
233
|
-
uid,
|
|
234
|
-
gid,
|
|
235
|
-
atime:
|
|
236
|
-
mtime:
|
|
237
|
-
isFile: () =>
|
|
238
|
-
isDirectory: () =>
|
|
239
|
-
isSymbolicLink: () =>
|
|
240
|
-
isBlockDevice: () =>
|
|
241
|
-
isCharacterDevice: () =>
|
|
242
|
-
isFIFO: () =>
|
|
243
|
-
isSocket: () =>
|
|
192
|
+
size: entry.size,
|
|
193
|
+
mode: parseModeFromLongname(entry.permissions),
|
|
194
|
+
uid: entry.uid,
|
|
195
|
+
gid: entry.gid,
|
|
196
|
+
atime: Math.floor(access?.timestamp / 1e3),
|
|
197
|
+
mtime: Math.floor(entry.timestamp / 1e3),
|
|
198
|
+
isFile: () => type === "-",
|
|
199
|
+
isDirectory: () => type === "d",
|
|
200
|
+
isSymbolicLink: () => type === "l",
|
|
201
|
+
isBlockDevice: () => type === "b",
|
|
202
|
+
isCharacterDevice: () => type === "c",
|
|
203
|
+
isFIFO: () => type === "p",
|
|
204
|
+
isSocket: () => type === "s"
|
|
244
205
|
};
|
|
245
206
|
}
|
|
207
|
+
stat(remotePath) {
|
|
208
|
+
return this.readStats(remotePath, "ldnL");
|
|
209
|
+
}
|
|
246
210
|
readlink(remotePath) {
|
|
247
211
|
return this.runCmd(`readlink "${remotePath}"`).then((output) => output.trim());
|
|
248
212
|
}
|
|
249
213
|
realpath(remotePath) {
|
|
250
214
|
return this.runCmd(`readlink -f "${remotePath}"`).then((output) => output.trim()).catch(() => this.runCmd(`cd "${remotePath}" && pwd`).then((output) => output.trim()));
|
|
251
215
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const isSymlink = output.trim().startsWith("l");
|
|
255
|
-
const lsOutput = await this.runCmd(`ls -la "${remotePath}"`);
|
|
256
|
-
const parts = lsOutput.trim().split(/\s+/);
|
|
257
|
-
if (parts.length < 9) {
|
|
258
|
-
return {
|
|
259
|
-
size: 0,
|
|
260
|
-
mode: 0,
|
|
261
|
-
uid: 0,
|
|
262
|
-
gid: 0,
|
|
263
|
-
atime: 0,
|
|
264
|
-
mtime: 0,
|
|
265
|
-
isFile: () => false,
|
|
266
|
-
isDirectory: () => false,
|
|
267
|
-
isSymbolicLink: () => false,
|
|
268
|
-
isBlockDevice: () => false,
|
|
269
|
-
isCharacterDevice: () => false,
|
|
270
|
-
isFIFO: () => false,
|
|
271
|
-
isSocket: () => false
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
const size = parseInt(parts[4], 10);
|
|
275
|
-
const modeStr = parts[0];
|
|
276
|
-
const mode = parseModeFromLongname(modeStr);
|
|
277
|
-
const uid = parseInt(parts[2], 10);
|
|
278
|
-
const gid = parseInt(parts[3], 10);
|
|
279
|
-
return {
|
|
280
|
-
size,
|
|
281
|
-
mode,
|
|
282
|
-
uid,
|
|
283
|
-
gid,
|
|
284
|
-
atime: 0,
|
|
285
|
-
mtime: 0,
|
|
286
|
-
isFile: () => !isSymlink && modeStr.startsWith("-"),
|
|
287
|
-
isDirectory: () => !isSymlink && modeStr.startsWith("d"),
|
|
288
|
-
isSymbolicLink: () => isSymlink,
|
|
289
|
-
isBlockDevice: () => modeStr.startsWith("b"),
|
|
290
|
-
isCharacterDevice: () => modeStr.startsWith("c"),
|
|
291
|
-
isFIFO: () => modeStr.startsWith("p"),
|
|
292
|
-
isSocket: () => modeStr.startsWith("s")
|
|
293
|
-
};
|
|
216
|
+
lstat(remotePath) {
|
|
217
|
+
return this.readStats(remotePath, "ldn");
|
|
294
218
|
}
|
|
295
219
|
chmod(remotePath, mode) {
|
|
296
220
|
return this.runCmd(`chmod ${this.maskMode(mode).toString(8)} "${remotePath}"`);
|
|
@@ -357,6 +281,30 @@ class SshFs {
|
|
|
357
281
|
}
|
|
358
282
|
}
|
|
359
283
|
}
|
|
284
|
+
function parseListing(output) {
|
|
285
|
+
return output.split("\n").flatMap((line) => {
|
|
286
|
+
const fields = /^([bcdlps-]\S*)\s+\d+\s+(\S+)\s+(\S+)\s+(\d+(?:,\s*\d+)?|0x[\da-fA-F]+)\s+(.+)$/.exec(line);
|
|
287
|
+
if (!fields) return [];
|
|
288
|
+
const [, permissions, uid, gid, size, tail] = fields;
|
|
289
|
+
const parsed = parseListingDate(tail);
|
|
290
|
+
if (!parsed) return [];
|
|
291
|
+
return [{ permissions, uid: Number(uid), gid: Number(gid), size: parseInt(size), ...parsed }];
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function parseListingDate(tail) {
|
|
295
|
+
const iso = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)?(?: ([+-]\d{4}))? (.+)$/.exec(tail);
|
|
296
|
+
if (iso) {
|
|
297
|
+
const [, date, time, fraction = "", zone = "Z", name] = iso;
|
|
298
|
+
return { timestamp: Date.parse(date + "T" + time + fraction.slice(0, 4) + zone), name };
|
|
299
|
+
}
|
|
300
|
+
const bsd = /^(\w{3})\s+(\d+) (\d{2}:\d{2}:\d{2}) (\d{4}) (.+)$/.exec(tail);
|
|
301
|
+
if (bsd) {
|
|
302
|
+
const [, month, day, time, year, name] = bsd;
|
|
303
|
+
return { timestamp: Date.parse(`${day} ${month} ${year} ${time} GMT`), name };
|
|
304
|
+
}
|
|
305
|
+
const brief = /^\w{3}\s+\d+\s+(?:\d{2}:\d{2}|\d{4}) (.+)$/.exec(tail);
|
|
306
|
+
return brief ? { timestamp: NaN, name: brief[1] } : void 0;
|
|
307
|
+
}
|
|
360
308
|
function createSshFs(session, options) {
|
|
361
309
|
return new SshFs(session, options);
|
|
362
310
|
}
|
package/dist/esm/transfer.d.ts
CHANGED
|
@@ -35,7 +35,6 @@ declare class SshFs {
|
|
|
35
35
|
private detectChunkSize;
|
|
36
36
|
private getExecOpts;
|
|
37
37
|
private maskMode;
|
|
38
|
-
private getMonthIndex;
|
|
39
38
|
private runCmd;
|
|
40
39
|
private rmFolderCmd;
|
|
41
40
|
private rmCmd;
|
|
@@ -51,11 +50,13 @@ declare class SshFs {
|
|
|
51
50
|
size: string;
|
|
52
51
|
count: number;
|
|
53
52
|
}>;
|
|
53
|
+
private readListings;
|
|
54
54
|
private listFiles;
|
|
55
55
|
list(remotePath: string): Promise<FileInfo[]>;
|
|
56
56
|
mkdir(remotePath: string, options?: {
|
|
57
57
|
mode?: number;
|
|
58
58
|
}): Promise<string>;
|
|
59
|
+
private readStats;
|
|
59
60
|
stat(remotePath: string): Promise<Stats>;
|
|
60
61
|
readlink(remotePath: string): Promise<string>;
|
|
61
62
|
realpath(remotePath: string): Promise<string>;
|