ensureSymlinkSync

import { ensureSymlinkSync } from "jsr:@ende/fs";

function

function ensureSymlinkSync(target: string | URL, linkName: string | URL): void

Synchronously ensures that the link exists, and points to a valid file.

If the parent directories for the link do not exist, they are created. If the link already exists, and it is not modified, this function does nothing. If the link already exists, and it does not point to the given target, an error is thrown.

Requires --allow-read and --allow-write permissions.

target: string | URL

The source file path as a string or URL. If it is a relative path string, it have to be relative to the link path.

linkName: string | URL

The destination link path as a string or URL.

Returns

A void value that returns once the link exists.

Example: Basic usage

import { ensureSymlinkSync } from "@ende/fs/ensure-symlink";

// Ensures the link `./targetFile.link.dat` exists and points to `./targetFile.dat`
ensureSymlinkSync("./targetFile.dat", "./targetFile.link.dat");

Example: Ensuring a link in a folder

import { ensureSymlinkSync } from "@ende/fs/ensure-symlink";

// Ensures the link `./folder/targetFile.link.dat` exists and points to `./folder/targetFile.dat`
ensureSymlinkSync("./targetFile.dat", "./folder/targetFile.link.dat");

See also

Source