From 4d58641eb7449ac88b423345e7d1b197c2ee6b4d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 2 Dec 2013 14:19:25 +0000 Subject: [PATCH] Do not overwrite config files. --- CMakeLists.txt | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a065291f4..2980e49bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,6 +235,32 @@ MACRO(FindLua _major _minor) ENDIF(ENABLE_LUAJIT MATCHES "ON") ENDMACRO(FindLua _major _minor) +FUNCTION(INSTALL_IF_NOT_EXISTS src dest) + IF(NOT IS_ABSOLUTE "${src}") + SET(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}") + ENDIF() + GET_FILENAME_COMPONENT(src_name "${src}" NAME) + IF(NOT IS_ABSOLUTE "${dest}") + SET(dest "${CMAKE_INSTALL_PREFIX}/${dest}") + ENDIF() + INSTALL(CODE " + IF(NOT EXISTS \"\$ENV{DESTDIR}${dest}/${src_name}\") + #FILE(INSTALL \"${src}\" DESTINATION \"${dest}\") + MESSAGE(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\") + EXECUTE_PROCESS(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" + \"\$ENV{DESTDIR}${dest}/${src_name}\" + RESULT_VARIABLE copy_result + ERROR_VARIABLE error_output) + IF(copy_result) + MESSAGE(FATAL_ERROR \${error_output}) + ENDIF() + ELSE() + MESSAGE(STATUS \"Skipping : \$ENV{DESTDIR}${dest}/${src_name}\") + ENDIF() + ") +ENDFUNCTION(INSTALL_IF_NOT_EXISTS) + + ############################# CONFIG SECTION ############################################# # Initial set @@ -1006,7 +1032,9 @@ SET(CONFFILES conf/options.conf conf/rspamd.conf conf/statistic.conf - conf/workers.conf) + conf/workers.conf + conf/2tld.inc + conf/surbl-whitelist.inc) ######################### LINK SECTION ############################### @@ -1085,11 +1113,14 @@ INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${CONFDIR})") INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${EXAMPLESDIR})") INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR}/lua)") -INSTALL(FILES conf/2tld.inc RENAME 2tld.inc DESTINATION ${CONFDIR}) - -INSTALL(FILES conf/surbl-whitelist.inc RENAME surbl-whitelist.inc DESTINATION ${CONFDIR}) - -INSTALL(FILES ${CONFFILES} DESTINATION ${CONFDIR}) +# Install configs only if they are unchanged +LIST(LENGTH CONFFILES CONFLIST_COUNT) +MATH(EXPR CONFLIST_MAX ${CONFLIST_COUNT}-1) + +FOREACH(CONF_IDX RANGE ${CONFLIST_MAX}) + LIST(GET CONFFILES ${CONF_IDX} CONF_FILE) + INSTALL_IF_NOT_EXISTS(${CONF_FILE} ${CONFDIR}) +ENDFOREACH(CONF_IDX RANGE ${CONFLIST_MAX}) # Lua plugins -- 2.39.5