Skip to contentSkip to conversation

git-p4: close temporary file before removing

PATCH In review Philip McGraw via GitGitGadget 2 participants 2 messages Aug 1, 2019

lore
Share & tools
lore
#0 lore raw

cover git-p4: close temporary file before removing

python os.remove() throws exceptions on Windows platform when attempting to remove file while still open.

Add local allocateTempFileName() to clarify that only the name is being allocated by NamedTemporaryFile(); file and handle are closed (but not deleted) when leave scope. Subsequent file deletion will succeed since file was closed.

Also print error details after resulting IOError to make debugging cause of exception less mysterious when it has nothing to do with "git version recent enough."

Philip.McGraw (1):
git-p4: close temporary file before removing

 git-p4.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

base-commit: 026dd738a6e5f1e42ef0f390feacb5ed6acc4ee8
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-301%2Fphilip-mcgraw%2Fgit-p4-close-temporary-file-before-remove-v2-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-301/philip-mcgraw/git-p4-close-temporary-file-before-remove-v2-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/301

Signature · 1 line
gitgitgadget
Reviewed-by Andrey Mazo on the v1 series
#1 lore raw

31.07.2019, 20:36, "Philip McGraw via GitGitGadget" <[email protected]>:

Quoted 7 lines

python os.remove() throws exceptions on Windows platform when attempting to remove file while still open.

Add local allocateTempFileName() to clarify that only the name is being allocated by NamedTemporaryFile(); file and handle are closed (but not deleted) when leave scope. Subsequent file deletion will succeed since file was closed.

I would also mention that this avoids double-open issue on Windows.

Quoted 9 lines

Also print error details after resulting IOError to make debugging cause of exception less mysterious when it has nothing to do with "git version recent enough."

Philip.McGraw (1):
  git-p4: close temporary file before removing

 git-p4.py | 21 ++++++++++++++-------

Quoted 8 lines
 1 file changed, 14 insertions(+), 7 deletions(-)

base-commit: 026dd738a6e5f1e42ef0f390feacb5ed6acc4ee8
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-301%2Fphilip-mcgraw%2Fgit-p4-close-temporary-file-before-remove-v2-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-301/philip-mcgraw/git-p4-close-temporary-file-before-remove-v2-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/301
--
gitgitgadget

Please, feel free to add

Thank you,
Andrey.