MantisBT - CMake
View Issue Details
0014713CMakeCMakepublic2014-01-20 11:062016-02-16 18:12
Alex Rettig 
Brad King 
normalminoralways
closedfixed 
Linux
 
CMake 3.0CMake 3.0 
0014713: cmake -create-symlink doesn't overwrite existing dangling(!) symlinks
Calling create_symlink for an existing target file doesn't replace the link.

Assuming there are no files "Target1" nor "Target2" in the current directory
cmake -E create_symlink Target1 Link
cmake -E create_symlink Target2 Link

should leave a link
Link -> Target2

but the result is
Link -> Target1

If 'Target1' exists, before calling the second "create_symlink", the behaviour is correct and results in 'Link -> Target2'

And yes, I have a use case, where I want to have a dangling symlink ;-)

See description.
See in cmake.cxx, where the case 'args[1] == "create_symlink"' is handled. Looks correct on the first sight, but:

most likely 'cmSystemTools::FileExists(destinationFileName)' doesn't return true for a dangling symlink 'destinationFileName', and therefore after the first 'if' statement the following code leading to '!cmSystemTools::RemoveFile(destinationFileName)' isn't executed.

Solution: distinguish correctly for symlinks, whether link or targed doesn't exist.

Or: remove the file 'destinationFileName' unconditionally.
No tags attached.
related to 0004418closed System Admin cmake -create-symlink doesn't overwrite existing symlinks 
related to 0014928closed  cmake -E create_symlink always returns code 0 even when failing to create symlink 
Issue History
2014-01-20 11:06Alex RettigNew Issue
2014-01-20 11:10Alex RettigNote Added: 0034974
2014-01-20 11:11Alex RettigNote Edited: 0034974bug_revision_view_page.php?bugnote_id=34974#r1374
2014-01-20 11:17Brad KingRelationship addedrelated to 0004418
2014-01-20 13:54Brad KingAssigned To => Brad King
2014-01-20 13:54Brad KingStatusnew => assigned
2014-01-20 13:54Brad KingTarget Version => CMake 3.0
2014-01-21 08:54Brad KingNote Added: 0034982
2014-01-21 08:55Brad KingStatusassigned => resolved
2014-01-21 08:55Brad KingResolutionopen => fixed
2014-01-21 08:55Brad KingFixed in Version => CMake 3.0
2014-05-23 13:39Brad KingRelationship addedrelated to 0014928
2014-05-26 06:19Alex RettigNote Added: 0035929
2014-05-26 06:19Alex RettigStatusresolved => closed

Notes
(0034974)
Alex Rettig   
2014-01-20 11:10   
(edited on: 2014-01-20 11:11)
Issue 0004418 dealt with the issue of overwriting symlinks already, but obviously didn't catch this cornercase.

(0034982)
Brad King   
2014-01-21 08:54   
I've committed a fix and new test cases to cover this:

 cmake: Improve '-E create_symlink' edge case handling
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e0228e2b [^]
(0035929)
Alex Rettig   
2014-05-26 06:19   
Thanks, Brad, I double checked with a freshly pulled version from today, found all variants I tested working correctly.