Function in io::fs compiler

read_link

fn read_link(string path) -> Result<string, IoError>
Import
use io::fs::{read_link};
Source: compiler/src/builtin_docs/io/fs.hy

Returns the target stored in the symbolic link at path.

The target is returned as written when the link was made (it may be relative and need not exist). Returns Err(IoError::InvalidInput) (or another error, depending on the OS) when path is not a link. Needs --allow-read.

Parameters#

NameType
pathstring

Returns#

Result<string, IoError>

Examples#

use io::fs::{read_link, remove_file, symlink};
use tests::assert;
let link = "/tmp/coil_doc_fs_read_link";
let _ = remove_file(link);
let _ = symlink("some/target.txt", link);
let target = match read_link(link) {
    Result::Ok(t) => t,
    Result::Err(_) => "",
};
let _ = remove_file(link);
assert!(target == "some/target.txt");

See also#

  • copy: Copies the contents of file from to to, creating or overwriting to.
  • create_dir: Creates the directory path.
  • create_dir_all: Creates the directory path and any missing parent directories.
  • exists: Returns whether anything exists at path.
  • is_dir: Returns whether path is a directory, following symbolic links.
  • is_file: Returns whether path is a regular file, following symbolic links.
  • is_symlink: Returns whether path itself is a symbolic link (the link is not followed).
  • list_dir: Returns the names of the entries in directory path, sorted.
↑ ↓ navigate ↵ open