Skip to content

Commit d20f0f8

Browse files
Pete Wyckoffgitster
authored andcommitted
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>
1 parent 4cea4d6 commit d20f0f8

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

git-p4.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import platform
2222
import re
2323
import shutil
24+
import stat
2425

2526
verbose = False
2627

@@ -1231,6 +1232,9 @@ def applyCommit(self, id):
12311232
p4_edit(dest)
12321233
pureRenameCopy.discard(dest)
12331234
filesToChangeExecBit[dest] = diff['dst_mode']
1235+
if self.isWindows:
1236+
# turn off read-only attribute
1237+
os.chmod(dest, stat.S_IWRITE)
12341238
os.unlink(dest)
12351239
editedFiles.add(dest)
12361240
elif modifier == "R":
@@ -1249,6 +1253,8 @@ def applyCommit(self, id):
12491253
p4_edit(dest) # with move: already open, writable
12501254
filesToChangeExecBit[dest] = diff['dst_mode']
12511255
if not self.p4HasMoveCommand:
1256+
if self.isWindows:
1257+
os.chmod(dest, stat.S_IWRITE)
12521258
os.unlink(dest)
12531259
filesToDelete.add(src)
12541260
editedFiles.add(dest)
@@ -1289,6 +1295,10 @@ def applyCommit(self, id):
12891295
for file in kwfiles:
12901296
if verbose:
12911297
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)
12921302
self.patchRCSKeywords(file, kwfiles[file])
12931303
fixed_rcs_keywords = True
12941304

0 commit comments

Comments
 (0)