git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git-p4: close temporary file before removing
@ 2019-07-30 17:37 Philip McGraw
  2019-07-31  1:48 ` Andrey
  0 siblings, 1 reply; 8+ messages in thread
From: Philip McGraw @ 2019-07-30 17:37 UTC (permalink / raw)
  To: git@vger.kernel.org

python os.remove() throws exceptions on Windows platform when attempting
to remove file while it is still open.  Need to grab filename while file open,
close file handle, then remove by name.  Apparently other platforms are more
permissive of removing files while busy.
reference: https://docs.python.org/3/library/os.html#os.remove
---
 git-p4.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/git-p4.py b/git-p4.py
index c71a6832e2..6b9d2a8317 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1161,12 +1161,14 @@ def exceedsLargeFileThreshold(self, relPath, contents):
                 return False
             contentTempFile = self.generateTempFile(contents)
             compressedContentFile = tempfile.NamedTemporaryFile(prefix='git-p4-large-file', delete=False)
+            compressedContentFileName = compressedContentFile.name
             zf = zipfile.ZipFile(compressedContentFile.name, mode='w')
             zf.write(contentTempFile, compress_type=zipfile.ZIP_DEFLATED)
             zf.close()
             compressedContentsSize = zf.infolist()[0].compress_size
             os.remove(contentTempFile)
-            os.remove(compressedContentFile.name)
+            compressedContentFile.close()
+            os.remove(compressedContentFileName)
             if compressedContentsSize > gitConfigInt('git-p4.largeFileCompressedThreshold'):
                 return True
         return False
--
2.21.0.windows.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-08-02  3:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30 17:37 [PATCH] git-p4: close temporary file before removing Philip McGraw
2019-07-31  1:48 ` Andrey
2019-07-31 13:53   ` Philip McGraw
2019-07-31 14:09     ` Andrey
2019-07-31 21:51       ` Philip McGraw
2019-08-01  1:34         ` Andrey
2019-08-01 15:30           ` Philip McGraw
2019-08-02  3:50             ` Andrey

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).