diff mbox series

[1/2] sstate.bbclass: factor out manifest cleanup code from sstate_clean_manifest()

Message ID 20230227154230.3566400-1-ovidiu.panait@eng.windriver.com
State New
Headers show
Series [1/2] sstate.bbclass: factor out manifest cleanup code from sstate_clean_manifest() | expand

Commit Message

Ovidiu Panait Feb. 27, 2023, 3:42 p.m. UTC
Move manifest entry cleanup code from sstate_clean_manifest() to its own
function, so it can be reused.

Signed-off-by: Ovidiu Panait <ovidiu.panait@eng.windriver.com>
---
 meta/classes-global/sstate.bbclass | 40 ++++++++++++++++--------------
 1 file changed, 22 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-global/sstate.bbclass b/meta/classes-global/sstate.bbclass
index 567de4aba4..af93546b04 100644
--- a/meta/classes-global/sstate.bbclass
+++ b/meta/classes-global/sstate.bbclass
@@ -501,6 +501,27 @@  def sstate_clean_cachefiles(d):
         ss = sstate_state_fromvars(ld, task)
         sstate_clean_cachefile(ss, ld)
 
+def sstate_clean_entry(entry, canrace, prefix):
+    entry = entry.strip()
+    if prefix and not entry.startswith("/"):
+        entry = prefix + "/" + entry
+
+    bb.debug(2, "Removing manifest: %s" % entry)
+    # We can race against another package populating directories as we're removing them
+    # so we ignore errors here.
+    try:
+        if entry.endswith("/"):
+            if os.path.islink(entry[:-1]):
+                os.remove(entry[:-1])
+            elif os.path.exists(entry) and len(os.listdir(entry)) == 0 and not canrace:
+                # Removing directories whilst builds are in progress exposes a race. Only
+                # do it in contexts where it is safe to do so.
+                os.rmdir(entry[:-1])
+        else:
+            os.remove(entry)
+    except OSError:
+        pass
+
 def sstate_clean_manifest(manifest, d, canrace=False, prefix=None):
     import oe.path
 
@@ -509,24 +530,7 @@  def sstate_clean_manifest(manifest, d, canrace=False, prefix=None):
     mfile.close()
 
     for entry in entries:
-        entry = entry.strip()
-        if prefix and not entry.startswith("/"):
-            entry = prefix + "/" + entry
-        bb.debug(2, "Removing manifest: %s" % entry)
-        # We can race against another package populating directories as we're removing them
-        # so we ignore errors here.
-        try:
-            if entry.endswith("/"):
-                if os.path.islink(entry[:-1]):
-                    os.remove(entry[:-1])
-                elif os.path.exists(entry) and len(os.listdir(entry)) == 0 and not canrace:
-                    # Removing directories whilst builds are in progress exposes a race. Only
-                    # do it in contexts where it is safe to do so.
-                    os.rmdir(entry[:-1])
-            else:
-                os.remove(entry)
-        except OSError:
-            pass
+        sstate_clean_entry(entry, canrace, prefix)
 
     postrm = manifest + ".postrm"
     if os.path.exists(manifest + ".postrm"):