[Cmake-commits] CMake branch, master, updated. v3.12.0-359-ge19453d

Kitware Robot kwrobot at kitware.com
Mon Aug 6 08:05:09 EDT 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, master has been updated
       via  e19453d8ec91d7694ceb4729d68574ccd183476e (commit)
       via  bdd0174df1d611c709dd2865d0f07fdd2ac9fa27 (commit)
      from  d1d5709503b0917ca0700c386f629d00d92d538e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e19453d8ec91d7694ceb4729d68574ccd183476e
commit e19453d8ec91d7694ceb4729d68574ccd183476e
Merge: d1d5709 bdd0174
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Mon Aug 6 11:55:16 2018 +0000
Commit:     Kitware Robot <kwrobot at kitware.com>
CommitDate: Mon Aug 6 07:55:24 2018 -0400

    Merge topic 'file-WRITE-chmod'
    
    bdd0174df1 file(WRITE): Avoid toggling permissions between 644 and 664
    
    Acked-by: Kitware Robot <kwrobot at kitware.com>
    Merge-request: !2246


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bdd0174df1d611c709dd2865d0f07fdd2ac9fa27
commit bdd0174df1d611c709dd2865d0f07fdd2ac9fa27
Author:     David Faure <faure at kde.org>
AuthorDate: Wed Aug 1 11:32:30 2018 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 1 09:05:33 2018 -0400

    file(WRITE): Avoid toggling permissions between 644 and 664
    
    On systems with umask 022, this function would set permissions
    to 664 and restore them to 644 at the end, every single time it was
    called (which is many times on e.g. install_manifest.txt).
    
    The intent of the code was to make non-writable files temporarily
    writable and to restore permissions in the end, but really, if it's
    already user-writable there's no point in toggling this back and forth.

diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 4c288f5..402ceb2 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -208,16 +208,20 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
   cmSystemTools::MakeDirectory(dir);
 
   mode_t mode = 0;
+  bool writable = false;
 
   // Set permissions to writable
   if (cmSystemTools::GetPermissions(fileName.c_str(), mode)) {
-    cmSystemTools::SetPermissions(fileName.c_str(),
 #if defined(_MSC_VER) || defined(__MINGW32__)
-                                  mode | S_IWRITE
+    writable = mode & S_IWRITE;
+    mode_t newMode = mode | S_IWRITE;
 #else
-                                  mode | S_IWUSR | S_IWGRP
+    writable = mode & S_IWUSR;
+    mode_t newMode = mode | S_IWUSR | S_IWGRP;
 #endif
-    );
+    if (!writable) {
+      cmSystemTools::SetPermissions(fileName.c_str(), newMode);
+    }
   }
   // If GetPermissions fails, pretend like it is ok. File open will fail if
   // the file is not writable
@@ -242,7 +246,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
     return false;
   }
   file.close();
-  if (mode) {
+  if (mode && !writable) {
     cmSystemTools::SetPermissions(fileName.c_str(), mode);
   }
   return true;
diff --git a/Source/cmWriteFileCommand.cxx b/Source/cmWriteFileCommand.cxx
index d3d2db0..c504ef4 100644
--- a/Source/cmWriteFileCommand.cxx
+++ b/Source/cmWriteFileCommand.cxx
@@ -45,16 +45,20 @@ bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args,
   cmSystemTools::MakeDirectory(dir);
 
   mode_t mode = 0;
+  bool writable = false;
 
   // Set permissions to writable
   if (cmSystemTools::GetPermissions(fileName.c_str(), mode)) {
-    cmSystemTools::SetPermissions(fileName.c_str(),
 #if defined(_MSC_VER) || defined(__MINGW32__)
-                                  mode | S_IWRITE
+    writable = mode & S_IWRITE;
+    mode_t newMode = mode | S_IWRITE;
 #else
-                                  mode | S_IWUSR | S_IWGRP
+    writable = mode & S_IWUSR;
+    mode_t newMode = mode | S_IWUSR | S_IWGRP;
 #endif
-    );
+    if (!writable) {
+      cmSystemTools::SetPermissions(fileName.c_str(), newMode);
+    }
   }
   // If GetPermissions fails, pretend like it is ok. File open will fail if
   // the file is not writable
@@ -69,7 +73,7 @@ bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args,
   }
   file << message << std::endl;
   file.close();
-  if (mode) {
+  if (mode && !writable) {
     cmSystemTools::SetPermissions(fileName.c_str(), mode);
   }
 

-----------------------------------------------------------------------

Summary of changes:
 Source/cmFileCommand.cxx      | 14 +++++++++-----
 Source/cmWriteFileCommand.cxx | 14 +++++++++-----
 2 files changed, 18 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list