Skip to content

Commit f67f218

Browse files
committed
fix: overwrite report file rather than unlink it when -f option is set
Since the introduction of landlock, we only have read-write permissions on the report and log files. We do not have the permission to unlink it, so we overwrite the content instead of unlinking the file.
1 parent 351545f commit f67f218

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

unblob/processing.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ def prepare_report_file(config: ExtractionConfig, report_file: Optional[Path]) -
194194

195195
if report_file.exists():
196196
if config.force_extract:
197-
logger.warning("Removing existing report file", path=report_file)
197+
logger.warning("Overwriting existing report file", path=report_file)
198198
try:
199-
report_file.unlink()
199+
report_file.write_text("")
200200
except OSError as e:
201201
logger.error(
202-
"Can not remove existing report file",
202+
"Can not overwrite existing report file",
203203
path=report_file,
204204
msg=str(e),
205205
)
@@ -209,15 +209,6 @@ def prepare_report_file(config: ExtractionConfig, report_file: Optional[Path]) -
209209
"Report file exists and --force not specified", path=report_file
210210
)
211211
return False
212-
213-
# check that the report directory can be written to
214-
try:
215-
report_file.write_text("")
216-
report_file.unlink()
217-
except OSError as e:
218-
logger.error("Can not create report file", path=report_file, msg=str(e))
219-
return False
220-
221212
return True
222213

223214

0 commit comments

Comments
 (0)