git p4: disable read-only attribute before deleting
On windows, p4 marks un-edited files as read-only. Not only are they read-only, but also they cannot be deleted. Remove the read-only attribute before deleting in both the copy and rename cases. This also happens in the RCS cleanup code, where a file is marked to be deleted, but must first be edited to remove adjust the keyword lines. Make sure it is editable before patching. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Jan 26, 2013 at 22:11 UTC
d20f0f8e2804bedc2c3743b523724ba7b8d34264
1 file changed
+10
git-p4.py
+10
@@ -21,6 +21,7 @@ import time
21
import platform
22
import re
23
import shutil
24
+import stat
25
26
verbose = False
27
@@ -1231,6 +1232,9 @@ class P4Submit(Command, P4UserMap):
1232
p4_edit(dest)
1233
pureRenameCopy.discard(dest)
1234
filesToChangeExecBit[dest] = diff['dst_mode']
1235
+ if self.isWindows:
1236
+ # turn off read-only attribute
1237
+ os.chmod(dest, stat.S_IWRITE)
1238
os.unlink(dest)
1239
editedFiles.add(dest)
1240
elif modifier == "R":
@@ -1249,6 +1253,8 @@ class P4Submit(Command, P4UserMap):
1253
p4_edit(dest) # with move: already open, writable
1254
filesToChangeExecBit[dest] = diff['dst_mode']
1255
if not self.p4HasMoveCommand:
1256
+ if self.isWindows:
1257
+ os.chmod(dest, stat.S_IWRITE)
1258
os.unlink(dest)
1259
filesToDelete.add(src)
1260
editedFiles.add(dest)
@@ -1289,6 +1295,10 @@ class P4Submit(Command, P4UserMap):
1295
for file in kwfiles:
1296
if verbose:
1297
print "zapping %s with %s" % (line,pattern)
1298
+ # File is being deleted, so not open in p4. Must
1299
+ # disable the read-only bit on windows.
1300
+ if self.isWindows and file not in editedFiles:
1301
+ os.chmod(file, stat.S_IWRITE)
1302
self.patchRCSKeywords(file, kwfiles[file])
1303
fixed_rcs_keywords = True
1304