From 848b34b3603ef0c56f06c40331b9a4c4400b941b Mon Sep 17 00:00:00 2001
From: Bartosz Kosiorek <gang65@poczta.onet.pl>
Date: Mon, 2 May 2016 12:27:57 +0200
Subject: [PATCH] Add support of multiple files for touch and touch_nocreate
 commands

---
 Help/manual/cmake.1.rst                            | 26 +++++++++++++++-------
 Source/cmcmd.cxx                                   | 21 +++++++++++------
 .../E_touch-three-not-existing-files-result.txt    |  1 +
 .../E_touch-three-not-existing-files-stderr.txt    |  0
 ...ch_nocreate-three-not-existing-files-result.txt |  1 +
 ...ch_nocreate-three-not-existing-files-stderr.txt |  0
 .../E_touch_three_not_existing_files-result.txt    |  1 +
 .../E_touch_three_not_existing_files-stderr.txt    |  0
 Tests/RunCMake/CommandLine/RunCMakeTest.cmake      | 11 ++++++++-
 9 files changed, 45 insertions(+), 16 deletions(-)
 create mode 100644 Tests/RunCMake/CommandLine/E_touch-three-not-existing-files-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_touch-three-not-existing-files-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_touch_nocreate-three-not-existing-files-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_touch_nocreate-three-not-existing-files-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_touch_three_not_existing_files-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_touch_three_not_existing_files-stderr.txt

diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst
index 5295a48c..8bae4aa 100644
--- a/Help/manual/cmake.1.rst
+++ b/Help/manual/cmake.1.rst
@@ -169,7 +169,7 @@ Available commands are:
 
 ``compare_files <file1> <file2>``
   Check if ``<file1>`` is same as ``<file2>``. If files are the same,
-  then returns 0, if not itreturns 1.
+  then returns 0, if not it returns 1.
 
 ``copy <file>... <destination>``
   Copy files to ``<destination>`` (either file or directory).
@@ -204,7 +204,12 @@ Available commands are:
   silently ignored.
 
 ``md5sum <file>...``
-  Compute md5sum of files.
+  Create MD5 checksum of files in ``md5sum`` compatible format
+
+  ::
+   cmake -E md5sum filetohash1.txt filetohash2.txt
+   351abe79cd3800b38cdfb25d45015a15  filetohash1.txt
+   052f86c15bbde68af55c7f7b340ab639  filetohash2.txt
 
 ``remove [-f] <file>...``
   Remove the file(s), use ``-f`` to force it.  If a file does
@@ -241,12 +246,17 @@ Available commands are:
 ``time <command> [<args>...]``
   Run command and return elapsed time.
 
-``touch <file>``
-  Touch a file.
-
-``touch_nocreate <file>``
-  Touch a file if it exists but do not create it.  If a file does
-  not exist it will be silently ignored.
+``touch <file>...``
+  Change <file> last access and modification times.
+  If <file> does not exist, it will be created with default
+  permissions. If error occurs during touching multiple files,
+  the operation will be continued for next files.
+
+``touch_nocreate <file>...``
+  Change <file> last access and modification times but do not create it.
+  If a <file> does not exist it will be silently ignored.
+  If error occurs during touching multiple files,
+  the operation will be continued for next files.
 
 UNIX-specific Command-Line Tools
 --------------------------------
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 19f3886..115514f 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -69,7 +69,7 @@ void CMakeCommandUsage(const char* program)
     << "                            - run command in a modified environment\n"
     << "  environment               - display the current environment\n"
     << "  make_directory <dir>...   - create parent and <dir> directories\n"
-    << "  md5sum <file>...          - compute md5sum of files\n"
+    << "  md5sum <file>...          - create MD5 checksum of files\n"
     << "  remove [-f] <file>...     - remove the file(s), use -f to force "
        "it\n"
     << "  remove_directory dir      - remove a directory and its contents\n"
@@ -79,8 +79,11 @@ void CMakeCommandUsage(const char* program)
     << "                            - create or extract a tar or zip archive\n"
     << "  sleep <number>...         - sleep for given number of seconds\n"
     << "  time command [args...]    - run command and return elapsed time\n"
-    << "  touch file                - touch a file.\n"
-    << "  touch_nocreate file       - touch a file but do not create it.\n"
+    << "  touch <file>...           - change <file> last access and "
+       "modification. If <file> does not exist, it is created with default "
+       "permissions\n"
+    << "  touch_nocreate <file>...  - change <file> last access and "
+       "modification, but do not create it\n"
 #if defined(_WIN32) && !defined(__CYGWIN__)
     << "Available on Windows only:\n"
     << "  delete_regv key           - delete registry value\n"
@@ -544,28 +547,32 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
     // Touch file
     else if (args[1] == "touch" && args.size() > 2)
       {
+      // If error occurs we want to continue touching next files.
+      bool return_value = 0;
       for (std::string::size_type cc = 2; cc < args.size(); cc ++)
         {
         if(!cmSystemTools::Touch(args[cc], true))
           {
-          return 1;
+          return_value = 1;
           }
         }
-      return 0;
+      return return_value;
       }
     // Touch file
     else if (args[1] == "touch_nocreate" && args.size() > 2)
       {
+      // If error occurs we want to continue touching next files.
+      bool return_value = 0;
       for (std::string::size_type cc = 2; cc < args.size(); cc ++)
         {
         // Complain if the file could not be removed, still exists,
         // and the -f option was not given.
         if(!cmSystemTools::Touch(args[cc], false))
           {
-          return 1;
+          return_value = 1;
           }
         }
-      return 0;
+      return return_value;
       }
 
     // Sleep command
diff --git a/Tests/RunCMake/CommandLine/E_touch-three-not-existing-files-result.txt b/Tests/RunCMake/CommandLine/E_touch-three-not-existing-files-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_touch-three-not-existing-files-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_touch-three-not-existing-files-stderr.txt b/Tests/RunCMake/CommandLine/E_touch-three-not-existing-files-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/E_touch_nocreate-three-not-existing-files-result.txt b/Tests/RunCMake/CommandLine/E_touch_nocreate-three-not-existing-files-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_touch_nocreate-three-not-existing-files-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_touch_nocreate-three-not-existing-files-stderr.txt b/Tests/RunCMake/CommandLine/E_touch_nocreate-three-not-existing-files-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/E_touch_three_not_existing_files-result.txt b/Tests/RunCMake/CommandLine/E_touch_three_not_existing_files-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_touch_three_not_existing_files-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_touch_three_not_existing_files-stderr.txt b/Tests/RunCMake/CommandLine/E_touch_three_not_existing_files-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index f449f1d..74b3090 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -10,7 +10,6 @@ run_cmake_command(U-no-arg ${CMAKE_COMMAND} -U)
 run_cmake_command(E-no-arg ${CMAKE_COMMAND} -E)
 run_cmake_command(E_echo_append ${CMAKE_COMMAND} -E echo_append)
 run_cmake_command(E_rename-no-arg ${CMAKE_COMMAND} -E rename)
-run_cmake_command(E_touch_nocreate-no-arg ${CMAKE_COMMAND} -E touch_nocreate)
 
 run_cmake_command(E_time ${CMAKE_COMMAND} -E time ${CMAKE_COMMAND} -E echo "hello  world")
 run_cmake_command(E_time-no-arg ${CMAKE_COMMAND} -E time)
@@ -159,6 +158,16 @@ run_cmake_command(E_make_directory-three-directories-and-file
 unset(out)
 unset(outfile)
 
+set(out ${RunCMake_BINARY_DIR}/touch_output)
+file(REMOVE_RECURSE "${out}")
+file(MAKE_DIRECTORY ${out})
+run_cmake_command(E_touch-three-not-existing-files
+  ${CMAKE_COMMAND} -E touch ${out}/f1 ${out}/f2 ${out}/f3)
+
+run_cmake_command(E_touch_nocreate-no-arg ${CMAKE_COMMAND} -E touch_nocreate)
+run_cmake_command(E_touch_nocreate-three-not-existing-files
+  ${CMAKE_COMMAND} -E touch_nocreate ${out}/f4 ${out}/f5 ${out}/f6)
+unset(out)
 
 run_cmake_command(E_env-no-command0 ${CMAKE_COMMAND} -E env)
 run_cmake_command(E_env-no-command1 ${CMAKE_COMMAND} -E env TEST_ENV=1)
-- 
2.6.4 (Apple Git-63)

