btca-server 2.0.2 → 2.0.4

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.
@@ -281,3 +281,76 @@ export const importDirectoryIntoVirtualFs = async (args: {
281
281
  await mkdirVirtualFs(dest, { recursive: true }, vfsId);
282
282
  await walk(base);
283
283
  };
284
+
285
+ export const importPathsIntoVirtualFs = async (args: {
286
+ sourcePath: string;
287
+ destinationPath: string;
288
+ relativePaths: readonly string[];
289
+ vfsId?: string;
290
+ }) => {
291
+ const base = path.resolve(args.sourcePath);
292
+ const dest = normalizeVfsPath(args.destinationPath);
293
+ const vfsId = args.vfsId;
294
+ const uniquePaths = Array.from(
295
+ new Set(
296
+ args.relativePaths
297
+ .map((relativePath) => relativePath.trim())
298
+ .filter((relativePath) => relativePath.length > 0 && relativePath !== '.')
299
+ )
300
+ ).sort((left, right) => left.localeCompare(right));
301
+
302
+ await mkdirVirtualFs(dest, { recursive: true }, vfsId);
303
+
304
+ for (const relativePath of uniquePaths) {
305
+ const sourcePath = path.join(base, relativePath);
306
+ const destinationPath = normalizeVfsPath(
307
+ posix.join(dest, relativePath.split(path.sep).join('/'))
308
+ );
309
+
310
+ let stat: Awaited<ReturnType<typeof fs.lstat>> | null = null;
311
+ try {
312
+ stat = await fs.lstat(sourcePath);
313
+ } catch {
314
+ stat = null;
315
+ }
316
+ if (!stat) continue;
317
+
318
+ await mkdirVirtualFs(posix.dirname(destinationPath), { recursive: true }, vfsId);
319
+
320
+ if (stat.isDirectory()) {
321
+ await mkdirVirtualFs(destinationPath, { recursive: true }, vfsId);
322
+ continue;
323
+ }
324
+
325
+ if (stat.isSymbolicLink()) {
326
+ let target: string | null = null;
327
+ try {
328
+ target = await fs.readlink(sourcePath);
329
+ } catch {
330
+ target = null;
331
+ }
332
+ if (!target) continue;
333
+ try {
334
+ await symlinkVirtualFs(target, destinationPath, vfsId);
335
+ } catch {
336
+ // Ignore invalid symlink entries while importing.
337
+ }
338
+ continue;
339
+ }
340
+
341
+ if (!stat.isFile()) continue;
342
+
343
+ let buffer: Buffer | null = null;
344
+ try {
345
+ buffer = await fs.readFile(sourcePath);
346
+ } catch {
347
+ buffer = null;
348
+ }
349
+ if (!buffer) continue;
350
+ try {
351
+ await writeVirtualFsFile(destinationPath, buffer, vfsId);
352
+ } catch {
353
+ // Ignore individual file write errors while importing.
354
+ }
355
+ }
356
+ };