bitbake-devel.lists.openembedded.org archive mirror
 help / color / mirror / Atom feed
From: Paulo Neves <paulo@myneves.com>
To: bitbake-devel@lists.openembedded.org
Cc: Paulo Neves <paulo@myneves.com>
Subject: [PATCH 5/5] git.py Replace mkdtemp with TemporaryDirectory and avoid exception masking
Date: Fri, 17 Feb 2023 17:01:16 +0000	[thread overview]
Message-ID: <20230217170009.58707-5-paulo@myneves.com> (raw)
In-Reply-To: <20230217170009.58707-1-paulo@myneves.com>

Due to using mkdtemp instead of TemporaryDirectory we needed to
manually cleanup the directory in a try finally block.
With tempfile.TemporaryDirectory we can handle the cleanup with
a "with" statement and not need to manually clean up oursevels.

Signed-off-by: Paulo Neves <paulo@myneves.com>
---
 lib/bb/fetch2/git.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index fcd70fdcf..9445643e5 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -417,8 +417,7 @@ class Git(FetchMethod):
             # It would be nice to just do this inline here by running 'git-lfs fetch'
             # on the bare clonedir, but that operation requires a working copy on some
             # releases of Git LFS.
-            tmpdir = tempfile.mkdtemp(dir=d.getVar('DL_DIR'))
-            try:
+            with tempfile.TemporaryDirectory(dir=d.getVar('DL_DIR')) as tmpdir:
                 # Do the checkout. This implicitly involves a Git LFS fetch.
                 Git.unpack(self, ud, tmpdir, d)

@@ -436,8 +435,6 @@ class Git(FetchMethod):
                 # downloaded.
                 if os.path.exists(os.path.join(tmpdir, "git", ".git", "lfs")):
                     runfetchcmd("tar -cf - lfs | tar -xf - -C %s" % ud.clonedir, d, workdir="%s/git/.git" % tmpdir)
-            finally:
-                bb.utils.remove(tmpdir, recurse=True)

     def build_mirror_data(self, ud, d):

--
2.34.1




  parent reply	other threads:[~2023-02-17 17:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 17:00 [PATCH 1/5] tests: git-lfs: Restore _find_git_lfs Paulo Neves
2023-02-17 17:00 ` [PATCH 2/5] test: Add real git lfs tests and decorator Paulo Neves
2023-02-17 17:00 ` [PATCH 3/5] git: Remove is None check on _find_git_lfs Paulo Neves
2023-02-22 12:03   ` [bitbake-devel] " Richard Purdie
2023-02-17 17:01 ` [PATCH 4/5] git.py: @_contains_lfs: Removed unused variables Paulo Neves
2023-02-17 17:01 ` Paulo Neves [this message]
2023-02-22 12:01 ` [bitbake-devel] [PATCH 1/5] tests: git-lfs: Restore _find_git_lfs Richard Purdie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230217170009.58707-5-paulo@myneves.com \
    --to=paulo@myneves.com \
    --cc=bitbake-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).