Skip to content

Commit

Permalink
Merge pull request #2520 from tom-tan/safe-file-isFile-isSymlink
Browse files Browse the repository at this point in the history
Make std.file.isFile, isSymlink and their unittests safe
  • Loading branch information
DmitryOlshansky committed Sep 20, 2014
2 parents 5fdfc20 + 6804896 commit 64e2233
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions std/file.d
Expand Up @@ -1245,15 +1245,15 @@ assert("/etc/fonts/fonts.conf".isFile);
assert(!"/usr/share/include".isFile);
--------------------
+/
@property bool isFile(in char[] name)
@property bool isFile(in char[] name) @safe
{
version(Windows)
return !name.isDir;
else version(Posix)
return (getAttributes(name) & S_IFMT) == S_IFREG;
}

unittest
@safe unittest
{
version(Windows)
{
Expand Down Expand Up @@ -1354,7 +1354,7 @@ bool attrIsFile(uint attributes) @safe pure nothrow @nogc
Throws:
$(D FileException) if the given file does not exist.
+/
@property bool isSymlink(C)(const(C)[] name)
@property bool isSymlink(in char[] name) @safe
{
version(Windows)
return (getAttributes(name) & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
Expand Down Expand Up @@ -1431,6 +1431,8 @@ unittest
assert(!attrIsFile(getLinkAttributes(symfile)));
}
}

static assert(__traits(compiles, () @safe { return "dummy".isSymlink; }));
}


Expand Down

0 comments on commit 64e2233

Please sign in to comment.