Skip to content

Commit 7505cc9

Browse files
committed
Veuillez saisir le message de validation pour vos modifications. Les lignes
commençant par '' seront ignorées, et un message vide abandonne la validation. Sur la branche less-deps-feature-win-tweaks Votre branche est à jour avec 'origin/less-deps-feature-win-tweaks'. Modifications qui seront validées : modifié : scripts/build-appimage.sh modifié : src/lufus/drives/formatting.py modifié : src/lufus/gui/i18n.py modifié : src/lufus/utils.py modifié : src/lufus/writing/flash_usb.py modifié : tests/test_flash_usb_and_find_usb_fixes.py
1 parent f30d249 commit 7505cc9

6 files changed

Lines changed: 43 additions & 21 deletions

File tree

scripts/build-appimage.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ ls -la
55

66
# Install system dependencies
77
echo "------------ Installing system libraries ------------"
8-
apt-get update && apt-get upgrade -y
98
INSTALLER="apt-get install -y"
109
if [[ -f requirements-system.txt ]]; then
1110
$INSTALLER $(cat requirements-system.txt) >> appimage-setup.log

src/lufus/drives/formatting.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,16 @@ def unmount(drive: str = None) -> bool:
104104
def remount(drive: str = None) -> bool:
105105
if not drive:
106106
mount, drive, _ = _get_mount_and_drive()
107+
else:
108+
# Look up mount point for the specified drive
109+
from lufus.drives.find_usb import find_usb
110+
mount_dict = find_usb()
111+
mount = mount_dict.get(drive)
107112
if not drive:
108113
log.error("No drive node found. Cannot unmount.")
109114
return False
110-
if not drive or not mount:
111-
log.error("No drive node or mount point found. Cannot remount.")
115+
if not mount:
116+
log.error("No mount point found for drive %s. Cannot remount.", drive)
112117
return False
113118
log.info("Remounting %s -> %s...", drive, mount)
114119
try:

src/lufus/gui/i18n.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ def load_translations(language="English"):
1111
return t
1212
lang_file = lang_dir / f"{language}.csv"
1313
if lang_file.exists():
14-
# read translations from csv :3
15-
with open(lang_file, encoding="utf-8", newline="") as f:
14+
# utf-8-sig strips BOM that some editors insert before the first byte.
15+
# Graceful row handling: skip malformed rows (no key column, empty key).
16+
with open(lang_file, encoding="utf-8-sig", newline="") as f:
1617
for row in csv.DictReader(f):
17-
t[row["key"]] = row["value"]
18+
key = row.get("key", "").strip()
19+
value = row.get("value", "").strip()
20+
if key:
21+
t[key] = value
1822
return t

src/lufus/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ def elevate_privileges() -> None:
1313
# if the app was able to find them before elevation.
1414
env = os.environ.copy()
1515
if state.theme:
16-
env["LUFUS_THEME"] = state.theme
16+
# Validate theme is a safe filename/path: no path separators, no "..",
17+
# and must be a basic filename to prevent path traversal.
18+
theme = os.path.basename(state.theme)
19+
if theme and theme == state.theme and ".." not in theme:
20+
env["LUFUS_THEME"] = theme
1721

1822
# Preserve DISPLAY and XAUTHORITY for GUI apps under pkexec/sudo
1923
env_vars = ["DISPLAY", "XAUTHORITY", "XDG_RUNTIME_DIR", "WAYLAND_DISPLAY", "PYTHONPATH", "LUFUS_THEME"]

src/lufus/writing/flash_usb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ def _status(msg: str) -> None:
124124
while True:
125125
chunk = process.stderr.read1(65536)
126126
if not chunk:
127+
# Flush any remaining partial stderr fragment so it is not lost
128+
if buf:
129+
decoded = buf.decode(errors="replace").rstrip("\r\n")
130+
if decoded:
131+
# Log at info to avoid alarming users with benign dd output
132+
log.info("dd stderr (final fragment): %s", decoded)
127133
break
128134
buf += chunk
129135
segments = re.split(rb"[\r\n]", buf)
@@ -155,7 +161,7 @@ def _status(msg: str) -> None:
155161
# dd bookkeeping lines — informational only, not progress events
156162
pass
157163
else:
158-
log.warning("dd stderr: %s", line_str)
164+
log.info("dd stderr: %s", line_str)
159165

160166
process.wait()
161167
_status(f"dd process exited with return code {process.returncode}")

tests/test_flash_usb_and_find_usb_fixes.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,11 @@ def test_progress_cb_receives_milestones_and_scaled_dd_progress(self, monkeypatc
385385
progress_values = []
386386
status_messages = []
387387

388-
def progress_cb(progress, status):
388+
def progress_cb(progress):
389389
progress_values.append(progress)
390-
status_messages.append(status)
390+
391+
def status_cb(message):
392+
status_messages.append(message)
391393

392394
stderr_lines = [
393395
"0+0 records in\n",
@@ -429,9 +431,9 @@ def progress_cb(progress, status):
429431
assert env.get("LC_ALL") == "C"
430432
assert dict(os.environ) == original_environ
431433

432-
# progress_cb should have the early 0.0 milestone, then scaled values
433-
assert progress_values[0] == 0.0
434-
assert progress_values[-1] == 1.0
434+
# progress_cb should have the early 0 milestone, then scaled values
435+
assert progress_values[0] == 0
436+
assert progress_values[-1] == 100
435437
assert sorted(progress_values) == progress_values
436438

437439
# Status messages should contain the raw dd progress lines
@@ -443,9 +445,11 @@ def test_non_progress_and_unexpected_stderr_lines_handling(self, monkeypatch, ca
443445
progress_values = []
444446
status_messages = []
445447

446-
def progress_cb(progress, status):
448+
def progress_cb(progress):
447449
progress_values.append(progress)
448-
status_messages.append(status)
450+
451+
def status_cb(message):
452+
status_messages.append(message)
449453

450454
stderr_lines = [
451455
"1+0 records in\n",
@@ -469,18 +473,18 @@ def progress_cb(progress, status):
469473
f.write(b"\x00" * 100)
470474
iso_path = f.name
471475

472-
with caplog.at_level("WARNING", logger="lufus"):
476+
with caplog.at_level("INFO", logger="lufus"):
473477
try:
474-
flash_usb_module.flash_usb("/dev/sdb", iso_path, progress_cb=progress_cb)
478+
flash_usb_module.flash_usb("/dev/sdb", iso_path, progress_cb=progress_cb, status_cb=status_cb)
475479
finally:
476480
os.unlink(iso_path)
477481

478-
# Only the initial 0.0 milestone should be present;
482+
# Only the initial 0 milestone should be present;
479483
# bookkeeping lines must not trigger additional progress_cb calls
480-
assert progress_values == [0.0]
484+
assert progress_values == [0]
481485

482-
# Unexpected stderr lines must surface as warnings
486+
# Non-progress stderr lines now log at info level
483487
unexpected_logs = [
484488
record for record in caplog.records if "some unexpected warning from dd" in record.getMessage()
485489
]
486-
assert unexpected_logs, "Unexpected stderr lines should produce a warning log entry"
490+
assert unexpected_logs, "Unexpected stderr lines should produce an info log entry"

0 commit comments

Comments
 (0)