[Issue 10174] New: std.file claims files which are symlinks to non-existant files don't exist

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 26 05:21:43 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10174

           Summary: std.file claims files which are symlinks to
                    non-existant files don't exist
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.philipp at gmail.com


--- Comment #0 from k.philipp at gmail.com 2013-05-26 05:21:42 PDT ---
The functions exists() and isSymlink() of std.file interact with symlinks in a
way that does not make sense to me. It seems the exists() function checks
whether the file pointed to by the symlink exists instead of the symlink
itself. I however think this is quite counter-intuitive as it leads to
situations where exists() returns false while isSymlink() returns true on the
same file if the symlink is broken. This behaviour is also not documented.

Here is a simple test case:

import std.file, std.stdio;

void main()
{
    auto file = "testfile";
    symlink("DOES-NOT-EXIST", file);
    writefln("exists: %b, isSymlink: %b", exists(file), isSymlink(file));
}

Which outputs:
exists: 0, isSymlink: 1
But should output:
exists: 1, isSymlink: 1


Maybe I am overlooking something here, but if not, I suggest the behaviour of
exists() to be changed to check the file itself and not the symlink target
(i.e. use lstat instead of stat) and maybe offer a function that explicitly
checks the referenced file in case of a symbolic link. Or, preserving
backwards-compatibility, introduce a new function that explicitly checks only
the file itself and properly document exists' behaviour.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list