techtonik / python-patch

Library to parse and apply unified diffs
https://pypi.python.org/pypi/patch
112 stars 64 forks source link

On unix-base systems patched file mode is not preserved #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.create a patch for an executable shell script
2.apply patch

What is the expected output? What do you see instead?
Target script must stay executable. Actually, its mode changes and executable 
permission

What version of the product are you using? On what operating system?
@146, python 2.6, Win and Mac

Original issue reported on code.google.com by azasyp...@gmail.com on 4 Apr 2011 at 7:19

GoogleCodeExporter commented 9 years ago
Suggested patch:

Index: patch.py
===================================================================
--- patch.py    (revision 146)
+++ patch.py    (working copy)
@@ -37,7 +37,9 @@
 from os.path import exists, isabs, isfile, abspath, normpath
 import os

+from stat import *

+
 #------------------------------------------------
 # Logging is controlled by "python_patch" logger

@@ -870,6 +872,7 @@

   def write_hunks(self, srcname, tgtname, hunks):
+    mode = os.stat(srcname)[ST_MODE]
     src = open(srcname, "rb")
     tgt = open(tgtname, "wb")

@@ -879,6 +882,9 @@

     tgt.close()
     src.close()
+    
+    if mode != os.stat(tgtname)[ST_MODE]:
+      os.chmod(tgtname, mode)
     return True

Original comment by azasyp...@gmail.com on 4 Apr 2011 at 7:46

GoogleCodeExporter commented 9 years ago
Good catch. Thanks. I'll integrate this as soon as I have an idea of a proper 
unittest for that.

Original comment by techtonik@gmail.com on 6 Apr 2011 at 9:05

GoogleCodeExporter commented 9 years ago

Original comment by techtonik@gmail.com on 10 Jan 2012 at 9:14

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r157.

Original comment by techtonik@gmail.com on 10 Jan 2012 at 11:38