From: "Anton D. Kachalov" <gmo...@google.com>

When running on read-only rootfs backed with overlayfs, the processed scripts
are being marked as deleted on upperdir of overlayfs. When it comes to
upgrade the main read-only image, it might contain new postinst scripts that
are different from the already processed. Introduced suffix (sha256 of
the content) allows to distinct updated scripts of the same package.

Signed-off-by: Anton D. Kachalov <gmo...@google.com>
---
 meta/lib/oe/package_manager/deb/rootfs.py   | 11 ++++++++++-
 meta/lib/oe/package_manager/ipk/rootfs.py   | 11 ++++++++++-
 meta/lib/oe/package_manager/rpm/__init__.py |  4 +++-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/meta/lib/oe/package_manager/deb/rootfs.py 
b/meta/lib/oe/package_manager/deb/rootfs.py
index 8fbaca11d6..704d213626 100644
--- a/meta/lib/oe/package_manager/deb/rootfs.py
+++ b/meta/lib/oe/package_manager/deb/rootfs.py
@@ -4,6 +4,7 @@
 
 import re
 import shutil
+from hashlib import sha256
 from oe.rootfs import Rootfs
 from oe.manifest import Manifest
 from oe.utils import execute_pre_post_process
@@ -115,8 +116,16 @@ class DpkgOpkgRootfs(Rootfs):
             bb.utils.mkdirhier(dst_postinst_dir)
 
             if os.path.exists(os.path.join(src_postinst_dir, p + ".postinst")):
+                csum = sha256()
+                with open(src_postinst_dir, p + ".postinst", "rb") as f:
+                    while True:
+                        data = f.read(65536)
+                        if not data:
+                            break
+                        csum.update(data)
+
                 shutil.copy(os.path.join(src_postinst_dir, p + ".postinst"),
-                            os.path.join(dst_postinst_dir, "%03d-%s" % (num, 
p)))
+                            os.path.join(dst_postinst_dir, "%03d-%s.%s" % 
(num, p, csum.hexdigest())))
 
             num += 1
 
diff --git a/meta/lib/oe/package_manager/ipk/rootfs.py 
b/meta/lib/oe/package_manager/ipk/rootfs.py
index 26dbee6f6a..6ead6ddef3 100644
--- a/meta/lib/oe/package_manager/ipk/rootfs.py
+++ b/meta/lib/oe/package_manager/ipk/rootfs.py
@@ -5,6 +5,7 @@
 import re
 import filecmp
 import shutil
+from hashlib import sha256
 from oe.rootfs import Rootfs
 from oe.manifest import Manifest
 from oe.utils import execute_pre_post_process
@@ -116,8 +117,16 @@ class DpkgOpkgRootfs(Rootfs):
             bb.utils.mkdirhier(dst_postinst_dir)
 
             if os.path.exists(os.path.join(src_postinst_dir, p + ".postinst")):
+                csum = sha256()
+                with open(src_postinst_dir, p + ".postinst", "rb") as f:
+                    while True:
+                        data = f.read(65536)
+                        if not data:
+                            break
+                        csum.update(data)
+
                 shutil.copy(os.path.join(src_postinst_dir, p + ".postinst"),
-                            os.path.join(dst_postinst_dir, "%03d-%s" % (num, 
p)))
+                            os.path.join(dst_postinst_dir, "%03d-%s.%s" % 
(num, p, csum.hexdigest())))
 
             num += 1
 
diff --git a/meta/lib/oe/package_manager/rpm/__init__.py 
b/meta/lib/oe/package_manager/rpm/__init__.py
index 6df0092281..4746e96ce8 100644
--- a/meta/lib/oe/package_manager/rpm/__init__.py
+++ b/meta/lib/oe/package_manager/rpm/__init__.py
@@ -4,6 +4,7 @@
 
 import shutil
 import subprocess
+from hashlib import sha256
 from oe.package_manager import *
 
 class RpmIndexer(Indexer):
@@ -359,7 +360,8 @@ class RpmPM(PackageManager):
         target_path = oe.path.join(self.target_rootfs, 
self.d.expand('${sysconfdir}/rpm-postinsts/'))
         bb.utils.mkdirhier(target_path)
         num = self._script_num_prefix(target_path)
-        saved_script_name = oe.path.join(target_path, "%d-%s" % (num, pkg))
+        csum = sha256(output.encode("utf-8")).hexdigest()
+        saved_script_name = oe.path.join(target_path, "%d-%s.%s" % (num, pkg, 
csum))
         open(saved_script_name, 'w').write(output)
         os.chmod(saved_script_name, 0o755)
 
-- 
2.31.0.rc2.261.g7f71774620-goog

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#149784): 
https://lists.openembedded.org/g/openembedded-core/message/149784
Mute This Topic: https://lists.openembedded.org/mt/81527936/21656
Group Owner: openembedded-core+ow...@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to