]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
sstate: Open file with context manager
authorOla x Nilsson <olani@axis.com>
Tue, 26 Aug 2025 13:41:34 +0000 (15:41 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 28 Aug 2025 09:47:02 +0000 (10:47 +0100)
In sstat_install and sstate_clean_cache.

Signed-off-by: Ola x Nilsson <olani@axis.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-global/sstate.bbclass

index e3d6373b3f473dbfc71fa488a2fc4547580abe01..2fd29d73232b7ecee4d52d7bc1f28e9a4c108582 100644 (file)
@@ -306,18 +306,17 @@ def sstate_install(ss, d):
         sharedfiles.append(ss['fixmedir'] + "/fixmepath")
 
     # Write out the manifest
-    f = open(manifest, "w")
-    for file in sharedfiles:
-        f.write(file + "\n")
-
-    # We want to ensure that directories appear at the end of the manifest
-    # so that when we test to see if they should be deleted any contents
-    # added by the task will have been removed first.
-    dirs = sorted(shareddirs, key=len)
-    # Must remove children first, which will have a longer path than the parent
-    for di in reversed(dirs):
-        f.write(di + "\n")
-    f.close()
+    with open(manifest, "w") as f:
+        for file in sharedfiles:
+            f.write(file + "\n")
+
+        # We want to ensure that directories appear at the end of the manifest
+        # so that when we test to see if they should be deleted any contents
+        # added by the task will have been removed first.
+        dirs = sorted(shareddirs, key=len)
+        # Must remove children first, which will have a longer path than the parent
+        for di in reversed(dirs):
+            f.write(di + "\n")
 
     # Append to the list of manifests for this PACKAGE_ARCH
 
@@ -481,9 +480,8 @@ def sstate_clean_cachefiles(d):
 def sstate_clean_manifest(manifest, d, canrace=False, prefix=None):
     import oe.path
 
-    mfile = open(manifest)
-    entries = mfile.readlines()
-    mfile.close()
+    with open(manifest) as mfile:
+        entries = mfile.readlines()
 
     for entry in entries:
         entry = entry.strip()