php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4180 is_link returns false when target doesnt exist (should return true)
Submitted: 2000-04-18 13:26 UTC Modified: 2002-10-01 15:03 UTC
From: dfarmer at evoke dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 3.0.14 OS: Linux 2.2.12-29.4smp #1 SMP Tue
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dfarmer at evoke dot com
New email:
PHP Version: OS:

 

 [2000-04-18 13:26 UTC] dfarmer at evoke dot com

It appears that is_link is incorrect when testing a symbolic link file whose target does not exist.

is_link("/absolute/path/to/my/link")

returns false when the link points to a non-existant target.  I believe it should return true based on the following C code:

#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>


main(int argc, char **argv)
{
    struct stat buf;
    char * file_name = argv[1];
    lstat(file_name, &buf);
    if (S_ISLNK(buf.st_mode))
    {
        printf("file is a link\n");
    }
    else
    {
        printf("file is not a link\n");
    }
}

This prints "file is a link" even when the target doesn't exist.   

This is an issue because you can't tell when the symlink already exists even if it is incorrect.  I've tried lstat (returns 0 length array), fileexists (false), etc.   symlink fails on the creation of the link because it is there.  It seems like the only way to detect this condition is to have a successful readlink call combined with a false file_exists or symlink call.   


The ChangeLog for 3.0.15 and 3.0.16 doesn't address this issue as being fixed.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-11 11:40 UTC] zak@php.net
Olivier Cahange <olivier.cahagne@epita.fr> reports this bug as being fixed in 4.0.3RC1
 [2000-10-11 12:58 UTC] zak@php.net
Minor typo in bug report number / forgot to engage brain :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 17:01:30 2025 UTC