The OpenD Programming Language

getLinkAttributes

If the given file is a symbolic link, then this returns the attributes of the symbolic link itself rather than file that it points to. If the given file is not a symbolic link, then this function returns the same result as getAttributes.

On Windows, getLinkAttributes is identical to getAttributes. It exists on Windows so that you don't have to special-case code for Windows when dealing with symbolic links.

  1. uint getLinkAttributes(R name)
  2. uint getLinkAttributes(R name)
    uint
    getLinkAttributes
    (
    R
    )
    (
    auto ref R name
    )

Parameters

name R

The file to get the symbolic link attributes of.

Return Value

Type: uint

the attributes

Throws

FileException on error.

Examples

import std.exception : assertThrown;

auto source = deleteme ~ "source";
auto target = deleteme ~ "target";

assert(!source.exists);
assertThrown!FileException(source.getLinkAttributes);

// symlinking isn't available on Windows
version (Posix)
{
    scope(exit) source.remove, target.remove;

    target.write("target");
    target.symlink(source);
    assert(source.readText == "target");
    assert(source.isSymlink);
    assert(source.getLinkAttributes.attrIsSymlink);
}

if the file is no symlink, getLinkAttributes behaves like getAttributes

import std.exception : assertThrown;

auto f = deleteme ~ "file";
scope(exit) f.remove;

assert(!f.exists);
assertThrown!FileException(f.getLinkAttributes);

f.write(".");
auto attributes = f.getLinkAttributes;
assert(!attributes.attrIsDir);
assert(attributes.attrIsFile);

if the file is no symlink, getLinkAttributes behaves like getAttributes

import std.exception : assertThrown;

auto dir = deleteme ~ "dir";
scope(exit) dir.rmdir;

assert(!dir.exists);
assertThrown!FileException(dir.getLinkAttributes);

dir.mkdir;
auto attributes = dir.getLinkAttributes;
assert(attributes.attrIsDir);
assert(!attributes.attrIsFile);

Meta