summaryrefslogtreecommitdiff
path: root/cli/js/ops/fs/symlink.ts
blob: 3bb7c3335aa591cf7d61088d51fa9b2e3c281d90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
import * as util from "../../util.ts";
import { build } from "../../build.ts";

/** **UNSTABLE**: `type` argument type may be changed to `"dir" | "file"`.
 *
 * Creates `newname` as a symbolic link to `oldname`. The type argument can be
 * set to `dir` or `file`. Is only available on Windows and ignored on other
 * platforms.
 *
 *       Deno.symlinkSync("old/name", "new/name");
 *
 * Requires `allow-read` and `allow-write` permissions. */
export function symlinkSync(
  oldname: string,
  newname: string,
  type?: string
): void {
  if (build.os === "win" && type) {
    return util.notImplemented();
  }
  sendSync("op_symlink", { oldname, newname });
}

/** **UNSTABLE**: `type` argument may be changed to "dir" | "file"
 *
 * Creates `newname` as a symbolic link to `oldname`. The type argument can be
 * set to `dir` or `file`. Is only available on Windows and ignored on other
 * platforms.
 *
 *       await Deno.symlink("old/name", "new/name");
 *
 * Requires `allow-read` and `allow-write` permissions. */
export async function symlink(
  oldname: string,
  newname: string,
  type?: string
): Promise<void> {
  if (build.os === "win" && type) {
    return util.notImplemented();
  }
  await sendAsync("op_symlink", { oldname, newname });
}