bdy 1.12.8-beta → 1.12.8-dev-pipeline-run

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 (156) hide show
  1. package/distTs/package.json +1 -1
  2. package/package.json +1 -1
  3. package/distTs/bin/cli.js +0 -5
  4. package/distTs/src/agent/agent.js +0 -328
  5. package/distTs/src/agent/linux.js +0 -124
  6. package/distTs/src/agent/manager.js +0 -519
  7. package/distTs/src/agent/osx.js +0 -146
  8. package/distTs/src/agent/socket/client.js +0 -178
  9. package/distTs/src/agent/socket/tunnel.js +0 -237
  10. package/distTs/src/agent/socket.js +0 -242
  11. package/distTs/src/agent/system.js +0 -179
  12. package/distTs/src/agent/wait.js +0 -23
  13. package/distTs/src/agent/windows.js +0 -159
  14. package/distTs/src/agent.js +0 -302
  15. package/distTs/src/api/agent.js +0 -99
  16. package/distTs/src/api/buddy.js +0 -139
  17. package/distTs/src/api/socket.js +0 -159
  18. package/distTs/src/cfg.js +0 -234
  19. package/distTs/src/command/agent/disable.js +0 -27
  20. package/distTs/src/command/agent/enable.js +0 -27
  21. package/distTs/src/command/agent/install.js +0 -117
  22. package/distTs/src/command/agent/restart.js +0 -27
  23. package/distTs/src/command/agent/run.js +0 -19
  24. package/distTs/src/command/agent/start.js +0 -28
  25. package/distTs/src/command/agent/status.js +0 -34
  26. package/distTs/src/command/agent/stop.js +0 -28
  27. package/distTs/src/command/agent/target/disable.js +0 -27
  28. package/distTs/src/command/agent/target/enable.js +0 -27
  29. package/distTs/src/command/agent/target/status.js +0 -32
  30. package/distTs/src/command/agent/target.js +0 -15
  31. package/distTs/src/command/agent/tunnel/http.js +0 -43
  32. package/distTs/src/command/agent/tunnel/list.js +0 -27
  33. package/distTs/src/command/agent/tunnel/remove.js +0 -28
  34. package/distTs/src/command/agent/tunnel/start.js +0 -34
  35. package/distTs/src/command/agent/tunnel/status.js +0 -31
  36. package/distTs/src/command/agent/tunnel/tcp.js +0 -43
  37. package/distTs/src/command/agent/tunnel/tls.js +0 -43
  38. package/distTs/src/command/agent/tunnel.js +0 -23
  39. package/distTs/src/command/agent/uninstall.js +0 -44
  40. package/distTs/src/command/agent/update.js +0 -38
  41. package/distTs/src/command/agent/version.js +0 -21
  42. package/distTs/src/command/agent.js +0 -35
  43. package/distTs/src/command/config/add/http.js +0 -25
  44. package/distTs/src/command/config/add/tcp.js +0 -25
  45. package/distTs/src/command/config/add/tls.js +0 -25
  46. package/distTs/src/command/config/add.js +0 -15
  47. package/distTs/src/command/config/get/region.js +0 -15
  48. package/distTs/src/command/config/get/timeout.js +0 -15
  49. package/distTs/src/command/config/get/token.js +0 -15
  50. package/distTs/src/command/config/get/tunnel.js +0 -19
  51. package/distTs/src/command/config/get/tunnels.js +0 -15
  52. package/distTs/src/command/config/get/whitelist.js +0 -15
  53. package/distTs/src/command/config/get.js +0 -21
  54. package/distTs/src/command/config/remove/tunnel.js +0 -19
  55. package/distTs/src/command/config/remove.js +0 -11
  56. package/distTs/src/command/config/set/region.js +0 -17
  57. package/distTs/src/command/config/set/timeout.js +0 -17
  58. package/distTs/src/command/config/set/token.js +0 -16
  59. package/distTs/src/command/config/set/whitelist.js +0 -17
  60. package/distTs/src/command/config/set.js +0 -17
  61. package/distTs/src/command/config.js +0 -17
  62. package/distTs/src/command/http.js +0 -30
  63. package/distTs/src/command/pre.js +0 -49
  64. package/distTs/src/command/start.js +0 -28
  65. package/distTs/src/command/tcp.js +0 -30
  66. package/distTs/src/command/tls.js +0 -30
  67. package/distTs/src/command/tunnel/config.js +0 -17
  68. package/distTs/src/command/tunnel/http.js +0 -31
  69. package/distTs/src/command/tunnel/start.js +0 -28
  70. package/distTs/src/command/tunnel/tcp.js +0 -30
  71. package/distTs/src/command/tunnel/tls.js +0 -30
  72. package/distTs/src/command/tunnel.js +0 -19
  73. package/distTs/src/command/ut/upload.js +0 -108
  74. package/distTs/src/command/ut.js +0 -12
  75. package/distTs/src/command/version.js +0 -13
  76. package/distTs/src/command/vt/close.js +0 -27
  77. package/distTs/src/command/vt/compare/validation.js +0 -173
  78. package/distTs/src/command/vt/compare.js +0 -97
  79. package/distTs/src/command/vt/exec.js +0 -81
  80. package/distTs/src/command/vt/installBrowser.js +0 -20
  81. package/distTs/src/command/vt/scrap.js +0 -193
  82. package/distTs/src/command/vt/storybook.js +0 -92
  83. package/distTs/src/command/vt.js +0 -22
  84. package/distTs/src/format.js +0 -174
  85. package/distTs/src/index.js +0 -34
  86. package/distTs/src/input.js +0 -270
  87. package/distTs/src/logger.js +0 -95
  88. package/distTs/src/output/interactive/tunnel.js +0 -860
  89. package/distTs/src/output/noninteractive/agent/tunnels.js +0 -43
  90. package/distTs/src/output/noninteractive/config/tunnel.js +0 -65
  91. package/distTs/src/output/noninteractive/config/tunnels.js +0 -18
  92. package/distTs/src/output/noninteractive/tunnel.js +0 -59
  93. package/distTs/src/output.js +0 -143
  94. package/distTs/src/server/cert.js +0 -52
  95. package/distTs/src/server/http1.js +0 -75
  96. package/distTs/src/server/http2.js +0 -78
  97. package/distTs/src/server/sftp.js +0 -497
  98. package/distTs/src/server/ssh.js +0 -446
  99. package/distTs/src/server/tls.js +0 -41
  100. package/distTs/src/ssh/client.js +0 -197
  101. package/distTs/src/texts.js +0 -421
  102. package/distTs/src/tunnel/agent.js +0 -103
  103. package/distTs/src/tunnel/api/agent.js +0 -100
  104. package/distTs/src/tunnel/api/buddy.js +0 -141
  105. package/distTs/src/tunnel/cfg.js +0 -243
  106. package/distTs/src/tunnel/compression.js +0 -44
  107. package/distTs/src/tunnel/dns.js +0 -53
  108. package/distTs/src/tunnel/html/503.html +0 -338
  109. package/distTs/src/tunnel/html.js +0 -33
  110. package/distTs/src/tunnel/http/log.js +0 -218
  111. package/distTs/src/tunnel/http/serve.js +0 -133
  112. package/distTs/src/tunnel/http/stream.js +0 -34
  113. package/distTs/src/tunnel/http.js +0 -508
  114. package/distTs/src/tunnel/identification.js +0 -103
  115. package/distTs/src/tunnel/latency.js +0 -83
  116. package/distTs/src/tunnel/output/interactive/tunnel.js +0 -867
  117. package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +0 -45
  118. package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +0 -67
  119. package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +0 -20
  120. package/distTs/src/tunnel/output/noninteractive/tunnel.js +0 -61
  121. package/distTs/src/tunnel/server/cert.js +0 -54
  122. package/distTs/src/tunnel/server/http1.js +0 -80
  123. package/distTs/src/tunnel/server/http2.js +0 -84
  124. package/distTs/src/tunnel/server/sftp.js +0 -514
  125. package/distTs/src/tunnel/server/ssh.js +0 -464
  126. package/distTs/src/tunnel/server/tls.js +0 -47
  127. package/distTs/src/tunnel/ssh/client.js +0 -211
  128. package/distTs/src/tunnel/tcp.js +0 -113
  129. package/distTs/src/tunnel/tunnel.js +0 -1010
  130. package/distTs/src/tunnel.js +0 -656
  131. package/distTs/src/types/ciInfo.js +0 -10
  132. package/distTs/src/types/options.js +0 -2
  133. package/distTs/src/types/plugin.js +0 -2
  134. package/distTs/src/types/queue.js +0 -2
  135. package/distTs/src/types/requests.js +0 -2
  136. package/distTs/src/types/resources.js +0 -2
  137. package/distTs/src/types/schemas.js +0 -54
  138. package/distTs/src/types/scrape.js +0 -2
  139. package/distTs/src/types/snapshots.js +0 -2
  140. package/distTs/src/types/storybook.js +0 -2
  141. package/distTs/src/types/tunnel.js +0 -141
  142. package/distTs/src/unitTest/ci.js +0 -108
  143. package/distTs/src/unitTest/requests.js +0 -72
  144. package/distTs/src/utils.js +0 -378
  145. package/distTs/src/visualTest/browser.js +0 -39
  146. package/distTs/src/visualTest/ci.js +0 -241
  147. package/distTs/src/visualTest/context.js +0 -52
  148. package/distTs/src/visualTest/exec.js +0 -51
  149. package/distTs/src/visualTest/linkUtils.js +0 -21
  150. package/distTs/src/visualTest/queue.js +0 -43
  151. package/distTs/src/visualTest/requests.js +0 -365
  152. package/distTs/src/visualTest/resources.js +0 -259
  153. package/distTs/src/visualTest/server.js +0 -109
  154. package/distTs/src/visualTest/snapshots.js +0 -129
  155. package/distTs/src/visualTest/utils/parseDom.js +0 -238
  156. package/distTs/src/visualTest/validation.js +0 -18
@@ -1,497 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const logger_1 = __importDefault(require("../logger"));
7
- const ssh2_1 = __importDefault(require("ssh2"));
8
- const promises_1 = __importDefault(require("fs/promises"));
9
- const path_1 = __importDefault(require("path"));
10
- const node_os_1 = require("node:os");
11
- const { flagsToString, STATUS_CODE } = ssh2_1.default.utils.sftp;
12
- class ServerSftp {
13
- constructor(sftp) {
14
- logger_1.default.debug('Creating sftp server');
15
- this.openHandlers = new Map();
16
- this.count = 0;
17
- this.sftp = sftp;
18
- this.sftp.on('OPEN', (reqId, fileName, flags, attrs) => this.open(reqId, fileName, flags, attrs));
19
- this.sftp.on('READ', (reqId, handle, offset, length) => this.read(reqId, handle, offset, length));
20
- this.sftp.on('WRITE', (reqId, handle, offset, data) => this.write(reqId, handle, offset, data));
21
- this.sftp.on('FSTAT', (reqId, handle) => this.fstat(reqId, handle));
22
- this.sftp.on('FSETSTAT', (reqId, handle, attrs) => this.fsetstat(reqId, handle, attrs));
23
- this.sftp.on('CLOSE', (reqId, handle) => this.close(reqId, handle));
24
- this.sftp.on('OPENDIR', (reqId, path) => this.opendir(reqId, path));
25
- this.sftp.on('READDIR', (reqId, handle) => this.readdir(reqId, handle));
26
- this.sftp.on('LSTAT', (reqId, path) => this.lstat(reqId, path));
27
- this.sftp.on('STAT', (reqId, path) => this.stat(reqId, path));
28
- this.sftp.on('REMOVE', (reqId, path) => this.remove(reqId, path));
29
- this.sftp.on('RMDIR', (reqId, path) => this.rmdir(reqId, path));
30
- this.sftp.on('REALPATH', (reqId, path) => this.realpath(reqId, path));
31
- this.sftp.on('READLINK', (reqId, path) => this.readlink(reqId, path));
32
- this.sftp.on('SETSTAT', (reqId, path, attrs) => this.setstat(reqId, path, attrs));
33
- this.sftp.on('MKDIR', (reqId, path, attrs) => this.mkdir(reqId, path, attrs));
34
- this.sftp.on('RENAME', (reqId, oldPath, newPath) => this.rename(reqId, oldPath, newPath));
35
- this.sftp.on('SYMLINK', (reqId, linkPath, targetPath) => this.symlink(reqId, linkPath, targetPath));
36
- }
37
- debugStart(txt) {
38
- logger_1.default.debug(txt);
39
- return process.hrtime();
40
- }
41
- debugEnd(txt, s, err) {
42
- const [seconds, nano] = process.hrtime(s);
43
- const ms = seconds * 1000 + nano / 1000 / 1000;
44
- logger_1.default.debug(`${txt} in ${ms}ms`);
45
- if (err)
46
- logger_1.default.debug(err);
47
- }
48
- async open(reqId, fileName, flags, attrs) {
49
- const s = this.debugStart(`SFTP want to open file ${fileName}`);
50
- try {
51
- const flag = flagsToString(flags);
52
- if (!flag) {
53
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
54
- this.debugEnd('SFTP open file failed', s);
55
- return;
56
- }
57
- const id = ++this.count;
58
- const handle = Buffer.alloc(4);
59
- handle.writeUint32BE(id, 0);
60
- const fd = await promises_1.default.open(fileName, flag);
61
- this.openHandlers.set(id, fd);
62
- await this._fsetstat(fd, attrs);
63
- this.sftp.handle(reqId, handle);
64
- this.debugEnd('SFTP open file succeed', s);
65
- }
66
- catch (err) {
67
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
68
- this.debugEnd('SFTP open file failed', s, err);
69
- }
70
- }
71
- async read(reqId, handle, offset, length) {
72
- const s = this.debugStart('SFTP want to read file');
73
- try {
74
- const id = handle.readUInt32BE(0);
75
- if (!this.openHandlers.has(id)) {
76
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
77
- this.debugEnd('SFTP read file failed', s);
78
- return;
79
- }
80
- const fd = this.openHandlers.get(id);
81
- const buffer = Buffer.alloc(length);
82
- const r = await fd.read(buffer, {
83
- offset: 0,
84
- length,
85
- position: offset,
86
- });
87
- if (r.bytesRead <= 0) {
88
- this.sftp.status(reqId, STATUS_CODE.EOF);
89
- }
90
- else if (r.bytesRead < length) {
91
- // strip buffer
92
- const buffer2 = Buffer.alloc(r.bytesRead);
93
- buffer.copy(buffer2, 0, 0, r.bytesRead);
94
- this.sftp.data(reqId, buffer2);
95
- }
96
- else {
97
- this.sftp.data(reqId, buffer);
98
- }
99
- this.debugEnd('SFTP read file succeed', s);
100
- }
101
- catch (err) {
102
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
103
- this.debugEnd('SFTP read file failed', s, err);
104
- }
105
- }
106
- async write(reqId, handle, offset, data) {
107
- const s = this.debugStart('SFTP want to write file');
108
- try {
109
- const id = handle.readUInt32BE(0);
110
- if (!this.openHandlers.has(id)) {
111
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
112
- this.debugEnd('SFTP write file failed', s);
113
- return;
114
- }
115
- const fd = this.openHandlers.get(id);
116
- await fd.write(data, 0, data.length, offset);
117
- this.sftp.status(reqId, STATUS_CODE.OK);
118
- this.debugEnd('SFTP write file succeed', s);
119
- }
120
- catch (err) {
121
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
122
- this.debugEnd('SFTP write file failed', s, err);
123
- }
124
- }
125
- async close(reqId, handle) {
126
- const s = this.debugStart('SFTP want to close handler');
127
- try {
128
- const id = handle.readUInt32BE(0);
129
- if (!this.openHandlers.has(id)) {
130
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
131
- this.debugEnd('SFTP close handler failed', s);
132
- return;
133
- }
134
- const fd = this.openHandlers.get(id);
135
- await fd.close();
136
- this.openHandlers.delete(id);
137
- this.sftp.status(reqId, STATUS_CODE.OK);
138
- this.debugEnd('SFTP closed handler succeed', s);
139
- }
140
- catch (err) {
141
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
142
- this.debugEnd('SFTP close handler failed', s, err);
143
- }
144
- }
145
- async fstat(reqId, handle) {
146
- const s = this.debugStart('SFTP want to stat file');
147
- try {
148
- const id = handle.readUInt32BE(0);
149
- if (!this.openHandlers.has(id)) {
150
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
151
- this.debugEnd('SFTP stat file failed', s);
152
- return;
153
- }
154
- const fd = this.openHandlers.get(id);
155
- const attrs = await fd.stat();
156
- this.sftp.attrs(reqId, attrs);
157
- this.debugEnd('SFTP stat file succeed', s);
158
- }
159
- catch (err) {
160
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
161
- this.debugEnd('SFTP stat file failed', s, err);
162
- }
163
- }
164
- async _fsetstat(fd, attrs) {
165
- if (Number.isInteger(attrs.uid) && Number.isInteger(attrs.gid)) {
166
- const s = this.debugStart(`SFTP want to chown with uid: ${attrs.uid}, gid: ${attrs.gid}`);
167
- try {
168
- await fd.chown(attrs.uid, attrs.gid);
169
- this.debugEnd('SFTP chown succeed', s);
170
- }
171
- catch (err) {
172
- this.debugEnd('SFTP chown failed', s, err);
173
- }
174
- }
175
- if (attrs.mode) {
176
- const s = this.debugStart(`SFTP want to chmod with mode: ${attrs.mode}`);
177
- try {
178
- await fd.chmod(attrs.mode);
179
- this.debugEnd('SFTP chmod succeed', s);
180
- }
181
- catch (err) {
182
- this.debugEnd('SFTP chmod failed', s, err);
183
- }
184
- }
185
- if (attrs.atime && attrs.mtime) {
186
- const s = this.debugStart(`SFTP want to utimes with atime: ${attrs.atime}, mtime: ${attrs.mtime}`);
187
- try {
188
- await fd.utimes(attrs.atime, attrs.mtime);
189
- this.debugEnd('SFTP utimes succeed', s);
190
- }
191
- catch (err) {
192
- this.debugEnd('SFTP utimes failed', s, err);
193
- }
194
- }
195
- }
196
- async fsetstat(reqId, handle, attrs) {
197
- const s = this.debugStart('SFTP want to set attrs of file');
198
- try {
199
- const id = handle.readUInt32BE(0);
200
- if (!this.openHandlers.has(id)) {
201
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
202
- this.debugEnd('SFTP set attrs of file failed', s);
203
- return;
204
- }
205
- const fd = this.openHandlers.get(id);
206
- await this._fsetstat(fd, attrs);
207
- this.sftp.status(reqId, STATUS_CODE.OK);
208
- this.debugEnd('SFTP set attrs of file succeed', s);
209
- }
210
- catch (err) {
211
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
212
- this.debugEnd('SFTP set attrs of file failed', s, err);
213
- }
214
- }
215
- async opendir(reqId, path) {
216
- const s = this.debugStart(`SFTP want to open directory ${path}`);
217
- try {
218
- const id = ++this.count;
219
- const handle = Buffer.alloc(4);
220
- handle.writeUint32BE(id, 0);
221
- const fd = await promises_1.default.opendir(path);
222
- this.openHandlers.set(id, fd);
223
- this.sftp.handle(reqId, handle);
224
- this.debugEnd('SFTP open directory succeed', s);
225
- }
226
- catch (err) {
227
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
228
- this.debugEnd('SFTP open directory failed', s, err);
229
- }
230
- }
231
- formatMode(mode) {
232
- const types = ['---', '--x', '-w-', '-wx', 'r--', 'r-x', 'rw-', 'rwx'];
233
- return [
234
- types[(mode >> 6) & 7],
235
- types[(mode >> 3) & 7],
236
- types[mode & 7],
237
- ].join('');
238
- }
239
- async longname(fullPath, name, stats) {
240
- // -rw-r--r-- 1 Michal staff 160543 Jul 29 09:31 cli.log
241
- const isDir = stats.isDirectory();
242
- const isLink = stats.isSymbolicLink();
243
- let displayName = name;
244
- if (isLink) {
245
- const link = await promises_1.default.readlink(fullPath);
246
- displayName = `${name} -> ${link}`;
247
- }
248
- return [
249
- isDir ? 'd' : isLink ? 'l' : '-',
250
- this.formatMode(stats.mode),
251
- ' ',
252
- (stats.nlink || 1).toString().padEnd(4),
253
- ' ',
254
- stats.uid.toString().padEnd(4),
255
- ' ',
256
- stats.gid.toString().padEnd(4),
257
- ' ',
258
- stats.size.toString().padStart(10),
259
- ' ',
260
- stats.mtime.toISOString().slice(0, 19).replace('T', ' '),
261
- ' ',
262
- displayName,
263
- ].join('');
264
- }
265
- async readdir(reqId, handle) {
266
- const s = this.debugStart('SFTP want to read directory');
267
- try {
268
- const id = handle.readUInt32BE(0);
269
- if (!this.openHandlers.has(id)) {
270
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
271
- this.debugEnd('SFTP read directory failed', s);
272
- return;
273
- }
274
- const fd = this.openHandlers.get(id);
275
- const names = [];
276
- let r = 0;
277
- const m = 1000;
278
- while (r < m) {
279
- const dir = await fd.read();
280
- if (!dir && !r) {
281
- this.sftp.status(reqId, STATUS_CODE.EOF);
282
- this.debugEnd('SFTP read directory ended', s);
283
- return;
284
- }
285
- else if (!dir) {
286
- break;
287
- }
288
- else {
289
- const name = dir.name;
290
- const fullPath = path_1.default.join(fd.path, name);
291
- const stat = await promises_1.default.lstat(fullPath);
292
- const longname = await this.longname(fullPath, name, stat);
293
- names.push({
294
- filename: name,
295
- longname,
296
- attrs: stat,
297
- });
298
- r += 1;
299
- }
300
- }
301
- this.sftp.name(reqId, names);
302
- this.debugEnd(`SFTP read directory ${fd.path} succeed`, s);
303
- }
304
- catch (err) {
305
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
306
- this.debugEnd('SFTP read directory failed', s, err);
307
- }
308
- }
309
- async stat(reqId, path) {
310
- const s = this.debugStart(`SFTP want to stat ${path}`);
311
- try {
312
- const attrs = await promises_1.default.stat(path);
313
- this.sftp.attrs(reqId, attrs);
314
- this.debugEnd('SFTP stat path succeed', s);
315
- }
316
- catch (err) {
317
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
318
- this.debugEnd('SFTP stat path failed', s, err);
319
- }
320
- }
321
- async remove(reqId, path) {
322
- const s = this.debugStart(`SFTP want to remove file ${path}`);
323
- try {
324
- await promises_1.default.rm(path);
325
- this.sftp.status(reqId, STATUS_CODE.OK);
326
- this.debugEnd('SFTP removed file succeed', s);
327
- }
328
- catch (err) {
329
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
330
- this.debugEnd('SFTP remove file failed', s, err);
331
- }
332
- }
333
- async rmdir(reqId, path) {
334
- const s = this.debugStart(`SFTP want to remove directory ${path}`);
335
- try {
336
- await promises_1.default.rmdir(path, {
337
- recursive: true,
338
- });
339
- this.sftp.status(reqId, STATUS_CODE.OK);
340
- this.debugEnd('SFTP remove directory succeed', s);
341
- }
342
- catch (err) {
343
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
344
- this.debugEnd('SFTP remove directory failed', s, err);
345
- }
346
- }
347
- async realpath(reqId, path) {
348
- const s = this.debugStart(`SFTP want realpath ${path}`);
349
- try {
350
- let p = path || '~/';
351
- if (p.includes('~')) {
352
- p = p.replaceAll('~', (0, node_os_1.homedir)());
353
- }
354
- const realPath = await promises_1.default.realpath(p);
355
- this.sftp.name(reqId, [
356
- {
357
- filename: realPath,
358
- },
359
- ]);
360
- this.debugEnd('SFTP realpath succeed', s);
361
- }
362
- catch (err) {
363
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
364
- this.debugEnd('SFTP realpath failed', s, err);
365
- }
366
- }
367
- async readlink(reqId, path) {
368
- const s = this.debugStart(`SFTP want readlink ${path}`);
369
- try {
370
- const realPath = await promises_1.default.readlink(path);
371
- this.sftp.name(reqId, [
372
- {
373
- filename: realPath,
374
- },
375
- ]);
376
- this.debugEnd('SFTP readlink succeed', s);
377
- }
378
- catch (err) {
379
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
380
- this.debugEnd('SFTP readlink failed', s, err);
381
- }
382
- }
383
- async _setstat(path, attrs) {
384
- if (Number.isInteger(attrs.uid) && Number.isInteger(attrs.gid)) {
385
- const s = this.debugStart(`SFTP want chown with uid: ${attrs.uid}, gid: ${attrs.gid}`);
386
- try {
387
- await promises_1.default.chown(path, attrs.uid, attrs.gid);
388
- this.debugEnd('SFTP chown succeed', s);
389
- }
390
- catch (err) {
391
- this.debugEnd('SFTP chown failed', s, err);
392
- }
393
- }
394
- if (attrs.mode) {
395
- const s = this.debugStart(`SFTP want to chmod with mode: ${attrs.mode}`);
396
- try {
397
- await promises_1.default.chmod(path, attrs.mode);
398
- this.debugEnd('SFTP chmod succeed', s);
399
- }
400
- catch (err) {
401
- this.debugEnd('SFTP chmod failed', s, err);
402
- }
403
- }
404
- if (attrs.atime && attrs.mtime) {
405
- const s = this.debugStart(`SFTP want to utimes with atime: ${attrs.atime}, mtime: ${attrs.mtime}`);
406
- try {
407
- await promises_1.default.utimes(path, attrs.atime, attrs.mtime);
408
- this.debugEnd('SFTP utimes succeed', s);
409
- }
410
- catch (err) {
411
- this.debugEnd('SFTP utimes failed', s, err);
412
- }
413
- }
414
- }
415
- async setstat(reqId, path, attrs) {
416
- const s = this.debugStart(`SFTP want to set attrs ${path}`);
417
- try {
418
- await this._setstat(path, attrs);
419
- this.sftp.status(reqId, STATUS_CODE.OK);
420
- this.debugEnd('SFTP set attrs succeed', s);
421
- }
422
- catch (err) {
423
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
424
- this.debugEnd('SFTP set attrs failed', s, err);
425
- }
426
- }
427
- async mkdir(reqId, path, attrs) {
428
- const s = this.debugStart(`SFTP want to create directory ${path}`);
429
- try {
430
- await promises_1.default.mkdir(path);
431
- await this._setstat(path, attrs);
432
- this.sftp.status(reqId, STATUS_CODE.OK);
433
- this.debugEnd('SFTP create directory succeed', s);
434
- }
435
- catch (err) {
436
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
437
- this.debugEnd('SFTP create directory failed', s, err);
438
- }
439
- }
440
- async rename(reqId, oldPath, newPath) {
441
- const s = this.debugStart(`SFTP want to rename path ${oldPath} to ${newPath}`);
442
- try {
443
- await promises_1.default.rename(oldPath, newPath);
444
- this.sftp.status(reqId, STATUS_CODE.OK);
445
- this.debugEnd('SFTP rename path succeed', s);
446
- }
447
- catch (err) {
448
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
449
- this.debugEnd('SFTP rename path failed', s, err);
450
- }
451
- }
452
- async symlink(reqId, linkPath, targetPath) {
453
- const s = this.debugStart(`SFTP want to symlink ${targetPath} at ${linkPath}`);
454
- try {
455
- await promises_1.default.symlink(targetPath, linkPath);
456
- this.sftp.status(reqId, STATUS_CODE.OK);
457
- this.debugEnd('SFTP symlink succeed', s);
458
- }
459
- catch (err) {
460
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
461
- this.debugEnd('SFTP symlink failed', s, err);
462
- }
463
- }
464
- async lstat(reqId, path) {
465
- const s = this.debugStart(`SFTP want to lstat ${path}`);
466
- try {
467
- const attrs = await promises_1.default.lstat(path);
468
- this.sftp.attrs(reqId, attrs);
469
- this.debugEnd('SFTP lstat path succeed', s);
470
- }
471
- catch (err) {
472
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
473
- this.debugEnd('SFTP lstat path failed', s, err);
474
- }
475
- }
476
- destroy() {
477
- if (this.sftp) {
478
- this.sftp.removeAllListeners();
479
- this.sftp.end();
480
- this.sftp = null;
481
- }
482
- if (this.openHandlers) {
483
- this.openHandlers.forEach((fd) => {
484
- try {
485
- fd.close();
486
- }
487
- catch {
488
- // do nothing
489
- }
490
- fd = null;
491
- });
492
- this.openHandlers = null;
493
- }
494
- this.count = 0;
495
- }
496
- }
497
- exports.default = ServerSftp;