From b0cc20a18630d98fed562f741c269f916d23fbc2 Mon Sep 17 00:00:00 2001 From: marcin- Date: Thu, 11 Jun 2026 12:41:32 +0200 Subject: [PATCH] Enable `PKGSYSTEM_ENABLE_FSYNC=0` optimization for HDDs during MIME database updates --- .../misc/shared-mime-info/comar/package.py | 9 +++- .../misc/shared-mime-info/comar/pakhandler.py | 44 ++++++++++++++++++- desktop/misc/shared-mime-info/pspec.xml | 7 +++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/desktop/misc/shared-mime-info/comar/package.py b/desktop/misc/shared-mime-info/comar/package.py index 81fb2db012..81e37dabeb 100644 --- a/desktop/misc/shared-mime-info/comar/package.py +++ b/desktop/misc/shared-mime-info/comar/package.py @@ -4,4 +4,11 @@ import os # Update global mime databases, mime database format may change (0.70) def postInstall(fromVersion, fromRelease, toVersion, toRelease): - os.system("/usr/bin/update-mime-database /usr/share/mime") + cmd = ( + "disk=$(findmnt -n -o SOURCE / | sed 's/[0-9]*$//'); " + "env $( [ -f \"/sys/block/${disk##*/}/queue/rotational\" ] && " + "[ \"$(cat \"/sys/block/${disk##*/}/queue/rotational\")\" = \"1\" ] && " + "echo PKGSYSTEM_ENABLE_FSYNC=0 ) " + "/usr/bin/update-mime-database /usr/share/mime" + ) + os.system(cmd) diff --git a/desktop/misc/shared-mime-info/comar/pakhandler.py b/desktop/misc/shared-mime-info/comar/pakhandler.py index 226588331a..90c88078ed 100644 --- a/desktop/misc/shared-mime-info/comar/pakhandler.py +++ b/desktop/misc/shared-mime-info/comar/pakhandler.py @@ -2,6 +2,47 @@ import piksemel import os +import re +import subprocess + +def is_root_on_hdd(): + """Returns True if the root partition (/) is located on an HDD.""" + try: + # 1. Get the source device for the mount point / + result = subprocess.run( + ["findmnt", "-n", "-o", "SOURCE", "/"], + capture_output=True, text=True, check=True + ) + source = result.stdout.strip() + if not source: + return False + + # 2. Strip the partition number (for /dev/sda1 -> /dev/sda, for /dev/nvme0n1p1 -> /dev/nvme0n1) + disk = re.sub(r'p?\d+$', '', source) # remove trailing digits and optional 'p' + disk_name = os.path.basename(disk) + + # 3. Check the contents of the rotational file + rotational_path = f"/sys/block/{disk_name}/queue/rotational" + if not os.path.exists(rotational_path): + return False + + with open(rotational_path, 'r') as f: + rotational = int(f.read().strip()) + + return rotational == 1 + + except Exception: + # On any error, assume it's not an HDD (variable won't be set) + return False + +def run_update_mime_database(path, use_fsync_opt): + """Runs /usr/bin/update-mime-database for the given path. + If use_fsync_opt is True, sets PKGSYSTEM_ENABLE_FSYNC=0.""" + cmd = ["/usr/bin/update-mime-database", path] + env = os.environ.copy() + if use_fsync_opt: + env["PKGSYSTEM_ENABLE_FSYNC"] = "0" + subprocess.run(cmd, env=env, check=False) def updateMimeTypes(filepath): parse = piksemel.parse(filepath) @@ -11,8 +52,9 @@ def updateMimeTypes(filepath): if "/share/mime/packages/" in path and path.endswith(".xml"): paths.add("/%s" % path.partition("packages/")[0]) + hdd = is_root_on_hdd() for p in paths: - os.system("/usr/bin/update-mime-database %s" % p) + run_update_mime_database(p, hdd) def setupPackage(metapath, filepath): updateMimeTypes(filepath) diff --git a/desktop/misc/shared-mime-info/pspec.xml b/desktop/misc/shared-mime-info/pspec.xml index 46e2e34992..8af7120e72 100644 --- a/desktop/misc/shared-mime-info/pspec.xml +++ b/desktop/misc/shared-mime-info/pspec.xml @@ -63,6 +63,13 @@ + + 2026-06-11 + 2.4 + Enable PKGSYSTEM_ENABLE_FSYNC=0 for rotational disks during mime db update + Marcin Bojara + marcin.bojara@gmail.com + 2023-11-16 2.4