www.digitalmars.com         C & C++   DMDScript  

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

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: k.philipp gmail.com



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: -------
May 26 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10174


Jameson <beatgammit gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |beatgammit gmail.com



I like the behavior of exists() because most of the time you only care that the
file can be read. Since a symlink is just a link to a file, the link itself
often doesn't mean that much.

I would, however, like a way to get at lstat() like the current dirEntry().
Perhaps I overlooked this as well?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10174




Yeah I can see how you would want symlinks to behave transparently by default.
Still getting this behaviour documented and a function that does lstat would be
nice.

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