This repository was archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpython-2.6.6-pathfix-preserve-timestamp.patch
57 lines (53 loc) · 1.93 KB
/
python-2.6.6-pathfix-preserve-timestamp.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
diff -up Python-2.6.6/Tools/scripts/pathfix.py.preserve-timestamp Python-2.6.6/Tools/scripts/pathfix.py
--- Python-2.6.6/Tools/scripts/pathfix.py.preserve-timestamp 2006-03-16 01:50:13.000000000 -0500
+++ Python-2.6.6/Tools/scripts/pathfix.py 2010-11-22 16:03:35.000000000 -0500
@@ -30,20 +30,24 @@ dbg = err
rep = sys.stdout.write
new_interpreter = None
+preserve_timestamps = False
def main():
global new_interpreter
+ global preserve_timestamps
usage = ('usage: %s -i /interpreter file-or-directory ...\n' %
sys.argv[0])
try:
- opts, args = getopt.getopt(sys.argv[1:], 'i:')
+ opts, args = getopt.getopt(sys.argv[1:], 'i:p')
except getopt.error, msg:
- err(msg + '\n')
+ err(str(msg) + '\n')
err(usage)
sys.exit(2)
for o, a in opts:
if o == '-i':
new_interpreter = a
+ if o == '-p':
+ preserve_timestamps = True
if not new_interpreter or new_interpreter[0] != '/' or not args:
err('-i option or file-or-directory missing\n')
err(usage)
@@ -119,8 +123,12 @@ def fix(filename):
# Finishing touch -- move files
# First copy the file's mode to the temp file
+ mtime = None
+ atime = None
try:
statbuf = os.stat(filename)
+ mtime = statbuf.st_mtime
+ atime = statbuf.st_atime
os.chmod(tempname, statbuf[ST_MODE] & 07777)
except os.error, msg:
err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
@@ -135,6 +143,13 @@ def fix(filename):
except os.error, msg:
err('%s: rename failed (%r)\n' % (filename, msg))
return 1
+ if preserve_timestamps:
+ if atime and mtime:
+ try:
+ os.utime(filename, (atime, mtime))
+ except os.error, msg:
+ err('%s: reset of timestamp failed (%r)\n' % (filename, msg))
+ return 1
# Return succes
return 0