Enable PKGSYSTEM_ENABLE_FSYNC=0 optimization for HDDs during MIME database updates

This commit is contained in:
marcin-
2026-06-11 12:41:32 +02:00
parent 75a836247c
commit b0cc20a186
3 changed files with 58 additions and 2 deletions
@@ -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)
@@ -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)
+7
View File
@@ -63,6 +63,13 @@
</Package>
<History>
<Update release="17">
<Date>2026-06-11</Date>
<Version>2.4</Version>
<Comment>Enable PKGSYSTEM_ENABLE_FSYNC=0 for rotational disks during mime db update</Comment>
<Name>Marcin Bojara</Name>
<Email>marcin.bojara@gmail.com</Email>
</Update>
<Update release="16">
<Date>2023-11-16</Date>
<Version>2.4</Version>