Skip to content

Commit 7115a18

Browse files
László Vaskóvlaci
authored andcommitted
chore(lint): enable flake8-logging-format ruff rules
- G004: Logging statement uses f-string - G010: Logging statement uses `warn` instead of `warning` https://beta.ruff.rs/docs/rules/#flake8-logging-format-g
1 parent cd1ff8a commit 7115a18

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ select = [
6969
"E", # pycodestyle (errors)
7070
"F", # pyflakes
7171
"FBT", # flake8-boolean-trap
72+
"G", # flake8-logging-format
7273
"I", # isort
7374
"ISC", # flake8-implicit-str-concats
7475
"N", # pep8-naming

unblob/extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def fix_symlink(path: Path, outdir: Path, task_result: TaskResult) -> Path:
5353
value).
5454
"""
5555
if is_recursive_link(path):
56-
logger.error(f"Symlink loop identified, removing {path}.")
56+
logger.error("Symlink loop identified, removing", path=path)
5757
error_report = MaliciousSymlinkRemoved(
5858
link=path.as_posix(), target=os.readlink(path)
5959
)
@@ -71,7 +71,7 @@ def fix_symlink(path: Path, outdir: Path, task_result: TaskResult) -> Path:
7171
safe = is_safe_path(outdir, target)
7272

7373
if not safe:
74-
logger.error(f"Path traversal attempt through symlink, removing {target}.")
74+
logger.error("Path traversal attempt through symlink, removing", target=target)
7575
error_report = MaliciousSymlinkRemoved(
7676
link=path.as_posix(), target=target.as_posix()
7777
)

unblob/handlers/archive/_safe_tarfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def extract(
1919
member_name_path = Path(str(member.name))
2020

2121
if not RUNNING_AS_ROOT and (member.ischr() or member.isblk()):
22-
logger.warn(
22+
logger.warning(
2323
"missing elevated permissions, skipping block and character device creation",
2424
path=member_name_path,
2525
)
2626
return
2727
if not is_safe_path(path_as_path, member_name_path):
28-
logger.warn("traversal attempt", path=member_name_path)
28+
logger.warning("traversal attempt", path=member_name_path)
2929
return
3030

3131
super().extract(member, path, set_attrs, numeric_owner=numeric_owner)

unblob/handlers/archive/xiaomi/hdr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def extract(self, inpath: Path, outdir: Path):
9898
with File.from_path(inpath) as file:
9999
for output_path, chunk in self.parse(file):
100100
if not is_safe_path(outdir, output_path):
101-
logger.warn(
101+
logger.warning(
102102
"Path traversal attempt, discarding.", output_path=output_path
103103
)
104104
return

unblob/handlers/filesystem/romfs.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def create_symlink(self, extract_root: Path, output_path: Path, inode: FileHeade
251251
target_path = extract_root.joinpath(target).resolve()
252252

253253
if not is_safe_path(extract_root, target_path):
254-
logger.warn(
254+
logger.warning(
255255
"Path traversal attempt through symlink.", target_path=target_path
256256
)
257257
return
@@ -268,24 +268,26 @@ def create_hardlink(self, extract_root: Path, link_path: Path, inode: FileHeader
268268
try:
269269
os.link(target_path, link_path)
270270
except FileNotFoundError:
271-
logger.warn(
271+
logger.warning(
272272
"Hard link target does not exist, discarding.",
273273
target_path=target_path,
274274
link_path=link_path,
275275
)
276276
except PermissionError:
277-
logger.warn(
277+
logger.warning(
278278
"Not enough privileges to create hardlink to block/char device, discarding.",
279279
target_path=target_path,
280280
link_path=link_path,
281281
)
282282
else:
283-
logger.warn("Invalid hard link target", inode_key=inode.spec_info)
283+
logger.warning("Invalid hard link target", inode_key=inode.spec_info)
284284

285285
def create_inode(self, extract_root: Path, inode: FileHeader):
286286
output_path = extract_root.joinpath(inode.path).resolve()
287287
if not is_safe_path(extract_root, inode.path):
288-
logger.warn("Path traversal attempt, discarding.", output_path=output_path)
288+
logger.warning(
289+
"Path traversal attempt, discarding.", output_path=output_path
290+
)
289291
return
290292
logger.info("dumping inode", inode=inode, output_path=str(output_path))
291293

@@ -314,7 +316,7 @@ def dump_fs(self):
314316
self.create_inode(self.extract_root, inode)
315317

316318
if os.geteuid() != 0:
317-
logger.warn(
319+
logger.warning(
318320
"root privileges are required to create block and char devices, skipping."
319321
)
320322
else:

unblob/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def default(self, obj):
192192
except UnicodeDecodeError:
193193
return str(obj)
194194

195-
logger.error(f"JSONEncoder met a non-JSON encodable value: {obj}")
195+
logger.error("JSONEncoder met a non-JSON encodable value", obj=obj)
196196
# the usual fail path of custom JSONEncoders is to call the parent and let it fail
197197
# return json.JSONEncoder.default(self, obj)
198198
# instead of failing, just return something usable

unblob/processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def _process_task(self, result: TaskResult, task: Task):
243243
return
244244

245245
if not valid_path(task.path):
246-
log.warn("Path contains invalid characters, it won't be processed")
246+
log.warning("Path contains invalid characters, it won't be processed")
247247
return
248248

249249
stat_report = StatReport.from_path(task.path)

0 commit comments

Comments
 (0)