[cmake-developers] [CMake 0014928]: cmake -E create_symlink always returns code 0 even when failing to create symlink

Mantis Bug Tracker mantis at public.kitware.com
Thu May 22 15:01:00 EDT 2014


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=14928 
====================================================================== 
Reported By:                dirk-thomas
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   14928
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2014-05-22 15:01 EDT
Last Modified:              2014-05-22 15:01 EDT
====================================================================== 
Summary:                    cmake -E create_symlink always returns code 0 even
when failing to create symlink
Description: 
When 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 Reproduce: 
Invoke "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 Information: 
I 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.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2014-05-22 15:01 dirk-thomas    New Issue                                    
======================================================================



More information about the cmake-developers mailing list