MantisBT - CMake
View Issue Details
0014022CMakeCMakepublic2013-03-18 10:402016-06-10 14:31
Petr Kmoch 
Kitware Robot 
normalminoralways
closedmoved 
Unix
CMake 2.8.9 
 
0014022: if(EXISTS) returns false for broken symlinks
'if(EXISTS arg)' evaluates to false if 'arg' is a symlink pointing to a non-existent file. To me, this feels like incorrect behaviour - arg itself exists, so the test should pass.

If the current behaviour is actually intended, I believe it should at least be documented.

With Windows symlinks, this does not happen; 'if(EXISTS arg)' evaluates to true if 'arg' is a broken link created with 'mklink'.
$ ln -s target link
$ cmake -P test_link.cmake (attached)
$ touch target
$ cmake -P test_link.cmake

'link' exists in both cases, but first run reports 'link does not exist'
No tags attached.
related to 0010468closed Brad King find_program() doesn't find not readable programs on *nix 
? test_link.cmake (114) 2013-03-18 10:40
https://public.kitware.com/Bug/file/4688/*
Issue History
2013-03-18 10:40Petr KmochNew Issue
2013-03-18 10:40Petr KmochFile Added: test_link.cmake
2013-03-18 10:57Brad KingRelationship addedrelated to 0010468
2013-03-18 11:05Brad KingNote Added: 0032656
2013-03-18 11:05Brad KingStatusnew => backlog
2013-03-26 08:27Brad KingNote Added: 0032702
2014-03-24 18:05Ben BoeckelNote Added: 0035496
2014-03-26 11:02Brad KingNote Added: 0035529
2016-06-10 14:28Kitware RobotNote Added: 0042253
2016-06-10 14:28Kitware RobotStatusbacklog => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0032656)
Brad King   
2013-03-18 11:05   
This is because the SystemTools::FileExists method:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/kwsys/SystemTools.cxx;hb=v2.8.10.2#l1080 [^]

uses "access" instead of "lstat" because someone once thought it was faster and so that find_* commands would only find readable files:

 http://public.kitware.com/gitweb?p=KWSys.git;a=commitdiff;h=4b0eccba [^]
 http://public.kitware.com/gitweb?p=KWSys.git;a=commitdiff;h=9fa7573f [^]

However, "access" should not be used for this purpose. Unfortunately it is hard to change now because many uses of FileExists have been introduced that assume its current behavior. Fixing this will require FileExists and all calls to it to be refactored into multiple functions that cover the actual needs of each call site. There are *many* such calls.
(0032702)
Brad King   
2013-03-26 08:27   
At least some code relies on if(EXISTS) returning false for a broken symlink:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Tests/CMakeLists.txt;hb=v2.8.10.2#l2195 [^]
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=46c0a583 [^]

Due to the historic "access()" implementation the if(EXISTS) check tests whether a file is readable. Any fix to this will have to preserve that, at least with a policy.
(0035496)
Ben Boeckel   
2014-03-24 18:05   
Would a policy or a new keyword (FILENAME_EXISTS) be better?
(0035529)
Brad King   
2014-03-26 11:02   
Re 0014022:0035496: I think a policy would be better. It will avoid carrying two almost identical interfaces and having to document the subtle difference.
(0042253)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.