Ticket #231 (new defect)

Opened 5 months ago

Last modified 4 months ago

File::exists() returns false on *existing* but broken symlinks

Reported by: Bruce Weirdan <weirdan@gmail.com> Assigned to: hans
Priority: minor Milestone:
Component: phing-core Version: devel
Keywords: Cc:

Description

This is because file_exists() reports broken symlinks as non-existent files:

[weirdan@server bin]$ ls -la
total 792
drwxr-xr-x  5 weirdan weirdan   4096 2008-03-05 00:36 .
drwxr-xr-x 12 weirdan weirdan   4096 2008-03-05 00:37 ..
drwxr-xr-x  6 weirdan weirdan   4096 2008-03-05 00:36 content
-rwxr-xr-x  1 weirdan weirdan 783673 2008-03-05 00:36 file
lrwxrwxrwx  1 weirdan weirdan      9 2008-03-05 12:10 php -> ../../php
drwxr-xr-x  5 weirdan weirdan   4096 2008-03-05 00:36 scheduler
drwxr-xr-x  6 weirdan weirdan   4096 2008-03-05 00:36 .svn
[weirdan@server bin]$ php -r 'var_dump(file_exists("php"));'
bool(false)
[weirdan@server bin]$ php -r 'var_dump(is_link("php"));'
bool(true)

In this example, there is no ../../php file, so symlink is broken.

Attachments

Change History

03/06/08 18:46:47 changed by cweiske@php.net

PHP's underlying functions behave the same way, so there is no way to detect that case.

03/06/08 19:43:20 changed by Bruce Weirdan <weirdan@gmail.com>

There is a way:

[weirdan@server bin]$ php -r 'var_dump(is_link("php") || file_exists("php"));'
bool(true)
[weirdan@server bin]$ php -r 'var_dump(is_link("does not exists") || file_exists("does not exists"));'
bool(false)

03/09/08 11:04:09 changed by mrook

Bruce, I'm not really sure on how you'd like Phing to behave on this one; a broken symlink is, for all intents and purposes, essentially a non-existing file.

03/09/08 20:26:16 changed by Bruce Weirdan <weirdan@gmail.com>

But most file operations could be performed on it, such as copying, moving, removing and so on. At the moment I was interested in copying and deleting symlinks - which I implemented myself. I will share my solution once I get enough time to prepare it and clean it up a bit.


Add/Change #231 (File::exists() returns false on *existing* but broken symlinks)