summaryrefslogtreecommitdiff
path: root/std/fs/copy.ts
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2020-04-29 22:00:31 +0200
committerGitHub <noreply@github.com>2020-04-29 16:00:31 -0400
commit3e6ea6284178df0be4982d9775f47b47b14c6139 (patch)
treeed684ea536e32023e72004110556ad8285126676 /std/fs/copy.ts
parent721a4ad59d4a8bdd8470d6b98839137f14c84ba9 (diff)
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.
Diffstat (limited to 'std/fs/copy.ts')
-rw-r--r--std/fs/copy.ts38
1 files changed, 19 insertions, 19 deletions
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);
}
}