From 3e6ea6284178df0be4982d9775f47b47b14c6139 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 29 Apr 2020 22:00:31 +0200 Subject: BREAKING: Include limited metadata in 'DirEntry' objects (#4941) This change is to prevent needed a separate stat syscall for each file when using readdir. For consistency, this PR also modifies std's `WalkEntry` interface to extend `DirEntry` with an additional `path` field. --- std/fs/copy.ts | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'std/fs/copy.ts') diff --git a/std/fs/copy.ts b/std/fs/copy.ts index 27b3c2a3c..d442e46ae 100644 --- a/std/fs/copy.ts +++ b/std/fs/copy.ts @@ -157,15 +157,15 @@ async function copyDir( await Deno.utime(dest, srcStatInfo.atime, srcStatInfo.mtime); } - for await (const file of Deno.readdir(src)) { - const srcPath = path.join(src, file.name); + for await (const entry of Deno.readdir(src)) { + const srcPath = path.join(src, entry.name); const destPath = path.join(dest, path.basename(srcPath as string)); - if (file.isDirectory) { + if (entry.isSymlink) { + await copySymLink(srcPath, destPath, options); + } else if (entry.isDirectory) { await copyDir(srcPath, destPath, options); - } else if (file.isFile) { + } else if (entry.isFile) { await copyFile(srcPath, destPath, options); - } else if (file.isSymlink) { - await copySymLink(srcPath, destPath, options); } } } @@ -185,16 +185,16 @@ function copyDirSync(src: string, dest: string, options: CopyOptions): void { Deno.utimeSync(dest, srcStatInfo.atime, srcStatInfo.mtime); } - for (const file of Deno.readdirSync(src)) { - assert(file.name != null, "file.name must be set"); - const srcPath = path.join(src, file.name); + for (const entry of Deno.readdirSync(src)) { + assert(entry.name != null, "file.name must be set"); + const srcPath = path.join(src, entry.name); const destPath = path.join(dest, path.basename(srcPath as string)); - if (file.isDirectory) { + if (entry.isSymlink) { + copySymlinkSync(srcPath, destPath, options); + } else if (entry.isDirectory) { copyDirSync(srcPath, destPath, options); - } else if (file.isFile) { + } else if (entry.isFile) { copyFileSync(srcPath, destPath, options); - } else if (file.isSymlink) { - copySymlinkSync(srcPath, destPath, options); } } } @@ -229,12 +229,12 @@ export async function copy( ); } - if (srcStat.isDirectory) { + if (srcStat.isSymlink) { + await copySymLink(src, dest, options); + } else if (srcStat.isDirectory) { await copyDir(src, dest, options); } else if (srcStat.isFile) { await copyFile(src, dest, options); - } else if (srcStat.isSymlink) { - await copySymLink(src, dest, options); } } @@ -268,11 +268,11 @@ export function copySync( ); } - if (srcStat.isDirectory) { + if (srcStat.isSymlink) { + copySymlinkSync(src, dest, options); + } else if (srcStat.isDirectory) { copyDirSync(src, dest, options); } else if (srcStat.isFile) { copyFileSync(src, dest, options); - } else if (srcStat.isSymlink) { - copySymlinkSync(src, dest, options); } } -- cgit v1.2.3