Skip to content

Commit 2e956f7

Browse files
committed
Merge branch 'pm/p4-auto-delete-named-temporary'
* pm/p4-auto-delete-named-temporary: git-p4: auto-delete named temporary file
2 parents d17f549 + de5abb5 commit 2e956f7

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

git-p4.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,13 +1160,11 @@ def exceedsLargeFileThreshold(self, relPath, contents):
11601160
if contentsSize <= gitConfigInt('git-p4.largeFileCompressedThreshold'):
11611161
return False
11621162
contentTempFile = self.generateTempFile(contents)
1163-
compressedContentFile = tempfile.NamedTemporaryFile(prefix='git-p4-large-file', delete=False)
1164-
zf = zipfile.ZipFile(compressedContentFile.name, mode='w')
1165-
zf.write(contentTempFile, compress_type=zipfile.ZIP_DEFLATED)
1166-
zf.close()
1167-
compressedContentsSize = zf.infolist()[0].compress_size
1163+
compressedContentFile = tempfile.NamedTemporaryFile(prefix='git-p4-large-file', delete=True)
1164+
with zipfile.ZipFile(compressedContentFile, mode='w') as zf:
1165+
zf.write(contentTempFile, compress_type=zipfile.ZIP_DEFLATED)
1166+
compressedContentsSize = zf.infolist()[0].compress_size
11681167
os.remove(contentTempFile)
1169-
os.remove(compressedContentFile.name)
11701168
if compressedContentsSize > gitConfigInt('git-p4.largeFileCompressedThreshold'):
11711169
return True
11721170
return False
@@ -3525,8 +3523,9 @@ def importHeadRevision(self, revision):
35253523
self.updateOptionDict(details)
35263524
try:
35273525
self.commit(details, self.extractFilesFromCommit(details), self.branch)
3528-
except IOError:
3526+
except IOError as err:
35293527
print("IO error with git fast-import. Is your git version recent enough?")
3528+
print("IO error details: {}".format(err))
35303529
print(self.gitError.read())
35313530

35323531
def openStreams(self):

0 commit comments

Comments
 (0)