diff options
author | Ali Hasani <a.hassssani@gmail.com> | 2020-05-19 03:16:02 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-19 00:46:02 +0200 |
commit | 6072755eadb7342a409f43260e5a17b956703a1c (patch) | |
tree | 35ec9b10eddafdc2b0dacecc439aa8d9f785529a /std/fs/copy.ts | |
parent | 88b24261ba467c20d4ef90224b07c19a71398f0f (diff) |
Implement Deno.symlink() for windows (#5533)
Diffstat (limited to 'std/fs/copy.ts')
-rw-r--r-- | std/fs/copy.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/std/fs/copy.ts b/std/fs/copy.ts index 8ebec3ae1..d45ac17c9 100644 --- a/std/fs/copy.ts +++ b/std/fs/copy.ts @@ -4,6 +4,8 @@ import { ensureDir, ensureDirSync } from "./ensure_dir.ts"; import { isSubdir, getFileInfoType } from "./_util.ts"; import { assert } from "../testing/asserts.ts"; +const isWindows = Deno.build.os === "windows"; + export interface CopyOptions { /** * overwrite existing file or directory. Default is `false` @@ -111,7 +113,13 @@ async function copySymLink( await ensureValidCopy(src, dest, options); const originSrcFilePath = await Deno.readLink(src); const type = getFileInfoType(await Deno.lstat(src)); - await Deno.symlink(originSrcFilePath, dest, type); + if (isWindows) { + await Deno.symlink(originSrcFilePath, dest, { + type: type === "dir" ? "dir" : "file", + }); + } else { + await Deno.symlink(originSrcFilePath, dest); + } if (options.preserveTimestamps) { const statInfo = await Deno.lstat(src); assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`); @@ -129,7 +137,14 @@ function copySymlinkSync( ensureValidCopySync(src, dest, options); const originSrcFilePath = Deno.readLinkSync(src); const type = getFileInfoType(Deno.lstatSync(src)); - Deno.symlinkSync(originSrcFilePath, dest, type); + if (isWindows) { + Deno.symlinkSync(originSrcFilePath, dest, { + type: type === "dir" ? "dir" : "file", + }); + } else { + Deno.symlinkSync(originSrcFilePath, dest); + } + if (options.preserveTimestamps) { const statInfo = Deno.lstatSync(src); assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`); |