[cmake-developers] [CPackDeb] use of internal md5sum function
Raffi Enficiaud
raffi.enficiaud at mines-paris.org
Mon Sep 14 08:52:59 EDT 2015
Hi Brad and Domen and others,
Please find attached a patch on CPackDeb
- which calls the internal function for md5sum computation
- which prevents the hash of the symlinks
I believe this fixes the issue (partially or totally)
https://public.kitware.com/Bug/view.php?id=13386
It is based on my previous patch.
Thanks,
Raffi
-------------- next part --------------
From 780a58a38d0445d1b4b58363b734a262a07a879e Mon Sep 17 00:00:00 2001
From: Raffi Enficiaud <raffi.enficiaud at mines-paris.org>
Date: Mon, 14 Sep 2015 14:45:12 +0200
Subject: [PATCH] CPackDeb: preventing md5sum on symlinks
- Direct call to cmSystemTools::ComputeFileMD5
- Avoiding hashing symlinks
- Tests
---
Source/CPack/cmCPackDebGenerator.cxx | 42 ++++++++++++----------
Tests/CPackComponentsDEB/CMakeLists.txt | 20 +++++++++++
...yResult-components-lintian-dpkgdeb-checks.cmake | 34 ++++++++++++++++++
.../CPackComponentsDEB/RunCPackVerifyResult.cmake | 12 +++++--
4 files changed, 86 insertions(+), 22 deletions(-)
diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx
index 981d86d..090c076 100644
--- a/Source/CPack/cmCPackDebGenerator.cxx
+++ b/Source/CPack/cmCPackDebGenerator.cxx
@@ -526,27 +526,31 @@ int cmCPackDebGenerator::createDeb()
packageFiles.begin();
fileIt != packageFiles.end(); ++ fileIt )
{
- std::string cmd = "\"";
- cmd += cmSystemTools::GetCMakeCommand();
- cmd += "\" -E md5sum \"";
- cmd += *fileIt;
- cmd += "\"";
-
- std::string output;
- int retval = -1;
- int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &output,
- &retval, toplevel.c_str(), this->GeneratorVerbose, 0);
- if ( !res || retval )
+
+ // hash only regular files
+ if( cmSystemTools::FileIsDirectory(*fileIt)
+ || cmSystemTools::FileIsSymlink(*fileIt))
{
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running cmake -E md5sum "
- << cmd << std::endl);
+ continue;
}
- // debian md5sums entries are like this:
- // 014f3604694729f3bf19263bac599765 usr/bin/ccmake
- // thus strip the full path (with the trailing slash)
- cmSystemTools::ReplaceString(output,
- topLevelWithTrailingSlash.c_str(), "");
- out << output;
+
+ char md5sum[33];
+ if(!cmSystemTools::ComputeFileMD5(*fileIt, md5sum))
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem computing the md5 of "
+ << *fileIt << std::endl);
+ }
+
+ md5sum[32] = 0;
+
+ std::string output(md5sum);
+ output += " " + *fileIt + "\n";
+ // debian md5sums entries are like this:
+ // 014f3604694729f3bf19263bac599765 usr/bin/ccmake
+ // thus strip the full path (with the trailing slash)
+ cmSystemTools::ReplaceString(output,
+ topLevelWithTrailingSlash.c_str(), "");
+ out << output;
}
// each line contains a eol.
// Do not end the md5sum file with yet another (invalid)
diff --git a/Tests/CPackComponentsDEB/CMakeLists.txt b/Tests/CPackComponentsDEB/CMakeLists.txt
index c25e33a..8ed81ac 100644
--- a/Tests/CPackComponentsDEB/CMakeLists.txt
+++ b/Tests/CPackComponentsDEB/CMakeLists.txt
@@ -93,6 +93,26 @@ if(CHMOD_PROG)
"${CMAKE_CURRENT_BINARY_DIR}/preinst;${CMAKE_CURRENT_BINARY_DIR}/prerm")
endif()
+# creates a symbolic link and a directory. Those should not be hashed.
+# warning: relocation of the symlink is not supported (symlinks with relative
+# paths)
+execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink mylibapp symtest)
+install(FILES ${CPackComponentsDEB_BINARY_DIR}/symtest
+ DESTINATION bin
+ COMPONENT applications)
+
+if(EXISTS "./dirtest")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ./dirtest)
+endif()
+execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ./dirtest)
+# BUG: apparently cannot add an empty directory
+execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../mylibapp ./dirtest/symtest)
+# NOTE: we should not add the trailing "/" to dirtest
+install(DIRECTORY ${CPackComponentsDEB_BINARY_DIR}/dirtest
+ DESTINATION bin/
+ COMPONENT applications)
+
+
# We may use the CPack specific config file in order
# to tailor CPack behavior on a CPack generator specific way
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake
index 5460b1a..c2b2417 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake
@@ -42,6 +42,13 @@ if(LINTIAN_EXECUTABLE)
ERROR_REGEX_STRINGS "${STRINGS_TO_AVOID}")
set(lintian_output_errors_all "${lintian_output_errors_all}${lintian_output_errors}")
+
+ set(STRINGS_TO_AVOID "E:([^\r\n]*)md5sums-lists-nonexistent-file")
+ lintian_check_specific_errors(lintian_output_errors
+ FILENAME "${_f}"
+ ERROR_REGEX_STRINGS "${STRINGS_TO_AVOID}")
+
+ set(lintian_output_errors_all "${lintian_output_errors_all}${lintian_output_errors}")
endforeach()
if(NOT "${lintian_output_errors_all}" STREQUAL "")
@@ -68,6 +75,33 @@ if(DPKGDEB_EXECUTABLE)
set(dpkgdeb_output_errors_all "${dpkgdeb_output_errors_all}"
"dpkg-deb: ${_f}: Incorrect value for Maintainer: ${dpkgentry} != None\n")
endif()
+
+ dpkgdeb_return_specific_metaentry(dpkg_package_name
+ DPKGDEB_OUTPUT "${dpkg_output}"
+ METAENTRY "Package:")
+
+ # specific to the component "applications"
+ if("${dpkg_package_name}" STREQUAL "mylib-applications")
+ run_dpkgdeb(dpkg_contents
+ FILENAME "${_f}"
+ ACTION "--contents"
+ )
+
+ string(FIND "${dpkg_contents}" "bin/symtest" index_symlink)
+ if(index_symlink EQUAL "-1")
+ set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all}
+ "dpkg-deb: ${_f}: symlink missing")
+ endif()
+
+ string(REGEX MATCH "(bin/dirtest/)([^\r\n]*)" index_directory "${dpkg_contents}")
+ if("${CMAKE_MATCH_1}" STREQUAL "")
+ set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all}
+ "dpkg-deb: ${_f}: directory 'bin/dirtest/' missing")
+ endif()
+
+ endif()
+
+
endforeach()
if(NOT "${dpkgdeb_output_errors_all}" STREQUAL "")
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake
index b96669e..bf9f81d 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake
@@ -137,6 +137,8 @@ endfunction()
# This function runs dpkg-deb on a .deb and returns its output
+# the default behaviour it to run "--info" on the specified Debian package
+# ACTION is one of the option accepted by dpkg-deb
function(run_dpkgdeb dpkg_deb_output)
set(${dpkg_deb_output} "" PARENT_SCOPE)
@@ -144,7 +146,7 @@ function(run_dpkgdeb dpkg_deb_output)
if(DPKGDEB_EXECUTABLE)
set(options "")
- set(oneValueArgs "FILENAME")
+ set(oneValueArgs "FILENAME" "ACTION")
set(multiValueArgs "")
cmake_parse_arguments(run_dpkgdeb_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
@@ -153,8 +155,12 @@ function(run_dpkgdeb dpkg_deb_output)
message(FATAL_ERROR "error: run_dpkgdeb needs FILENAME to be set")
endif()
- # run lintian
- execute_process(COMMAND ${DPKGDEB_EXECUTABLE} -I ${run_dpkgdeb_deb_FILENAME}
+ if(NOT run_dpkgdeb_deb_ACTION)
+ set(run_dpkgdeb_deb_ACTION "--info")
+ endif()
+
+ # run dpkg-deb
+ execute_process(COMMAND ${DPKGDEB_EXECUTABLE} ${run_dpkgdeb_deb_ACTION} ${run_dpkgdeb_deb_FILENAME}
WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
OUTPUT_VARIABLE DPKGDEB_OUTPUT
RESULT_VARIABLE DPKGDEB_RESULT
--
1.9.1
More information about the cmake-developers
mailing list