View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014928CMakeCMakepublic2014-05-22 15:012016-02-16 13:11
Reporterdirk-thomas 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformLinuxOSUbuntuOS Version14.04
Product VersionCMake 2.8.12.2 
Target VersionFixed in VersionCMake 3.0 
Summary0014928: cmake -E create_symlink always returns code 0 even when failing to create symlink
DescriptionWhen invoking the command "cmake -E create_symlink old new" the return code is always 0 even when the command failed to create the symlink.
Steps To ReproduceInvoke "cmake ." with the following CMakeLists.txt file in the same folder to reproduce:

# create a real file
set(file "${CMAKE_CURRENT_SOURCE_DIR}/test")
file(WRITE "${file}" "foo")
if(EXISTS "${file}" AND NOT IS_SYMLINK "${file}")
  message(STATUS "OK: it is a file, not a symlink")
else()
  message(FATAL_ERROR "ups, this hould not happen")
endif()

# try to create a symlink
execute_process(
  COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "/tmp/somewhere" "${file}"
  RESULT_VARIABLE rc
  OUTPUT_VARIABLE output
  ERROR_VARIABLE error
)
message(STATUS "RESULT_VARIABLE ${rc}")
message(STATUS "OUTPUT_VARIABLE ${output}")
message(STATUS "ERROR_VARIABLE ${error}")

if(EXISTS "${file}" AND IS_SYMLINK "${file}")
  message(STATUS "WEIRD: it is a symlink, not a file, has overwritten the existing file")
elseif(NOT rc EQUAL 0)
  message(STATUS "OK: could not create symlink and returned error code")
else()
  message(FATAL_ERROR "ups, this hould not happen, not creating the symlink but returning code 0 pretending it was successful")
endif()
Additional InformationI currently manually have to check that neither a symlink nor file is present before invoking the command and check afterwards that the symlink is present.
TagsNo tags attached.
Attached Files

 Relationships
related to 0014713closedBrad King cmake -create-symlink doesn't overwrite existing dangling(!) symlinks 

  Notes
(0035919)
Brad King (manager)
2014-05-23 08:52

Look at the actual directory content with "ls" after running your example. A symlink called "test" exists and points to /tmp/somewhere. Creation of the symlink worked.

The problem in your example is that if(EXISTS) returns FALSE for a broken symlink. See 0014022.
(0035923)
dirk-thomas (reporter)
2014-05-23 12:37
edited on: 2014-05-23 12:37

You seem to get a different result then me. After I run it there is no symlink but still the dummy file with the content "foo". I added the messages in CMake only to illustrate the actual and expected behavior.

The same happens for me even when I remove the "EXISTS" check you refer to:

# create a real file
set(file "${CMAKE_CURRENT_SOURCE_DIR}/test")
file(WRITE "${file}" "foo")
if(EXISTS "${file}" AND NOT IS_SYMLINK "${file}")
  message(STATUS "OK: it is a file, not a symlink")
else()
  message(FATAL_ERROR "ups, this hould not happen")
endif()

# try to create a symlink
execute_process(
  COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "/tmp/somewhere" "${file}"
  RESULT_VARIABLE rc
  OUTPUT_VARIABLE output
  ERROR_VARIABLE error
)
message(STATUS "RESULT_VARIABLE ${rc}")
message(STATUS "OUTPUT_VARIABLE ${output}")
message(STATUS "ERROR_VARIABLE ${error}")

if(IS_SYMLINK "${file}")
  message(STATUS "WEIRD: it is a symlink, not a file, has overwritten the existing file")
elseif(NOT rc EQUAL 0)
  message(STATUS "OK: could not create symlink and returned error code")
else()
  message(FATAL_ERROR "ups, this hould not happen, not creating the symlink but returning code 0 pretending it was successful")
endif()

(0035924)
Brad King (manager)
2014-05-23 13:33

Behavior has changed since 2.8.12.2. See 0014713 and this commit for it:

 cmake: Improve '-E create_symlink' edge case handling
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e0228e2b [^]
(0035925)
Brad King (manager)
2014-05-23 13:34

You can try a CMake 3.0 release candidate here:

 http://www.cmake.org/files/v3.0/?C=M;O=D [^]
(0035926)
dirk-thomas (reporter)
2014-05-23 13:37

I guess the ticket can be closed then and marked with "fixed in 3.0". Thanks!
(0037141)
Robert Maynard (manager)
2014-11-03 08:38

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2014-05-22 15:01 dirk-thomas New Issue
2014-05-23 08:52 Brad King Note Added: 0035919
2014-05-23 12:37 dirk-thomas Note Added: 0035923
2014-05-23 12:37 dirk-thomas Note Edited: 0035923
2014-05-23 13:33 Brad King Note Added: 0035924
2014-05-23 13:34 Brad King Note Added: 0035925
2014-05-23 13:37 dirk-thomas Note Added: 0035926
2014-05-23 13:39 Brad King Relationship added related to 0014713
2014-05-23 13:39 Brad King Status new => resolved
2014-05-23 13:39 Brad King Resolution open => fixed
2014-05-23 13:39 Brad King Fixed in Version => CMake 3.0
2014-11-03 08:38 Robert Maynard Note Added: 0037141
2014-11-03 08:38 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team