Skip to content

Commit 5d002d0

Browse files
committed
sample_compare: race conditions
1 parent 8bce8ee commit 5d002d0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

library/files/sample_compare.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import hashlib
22
from concurrent.futures import ThreadPoolExecutor
3+
from contextlib import suppress
34
from pathlib import Path
45

56
from library import usage
@@ -47,7 +48,10 @@ def sample_cmp(*paths, threads=1, gap=0.1, chunk_size=None, ignore_holes=False,
4748
if len(paths) < 2:
4849
raise ValueError("Not enough paths. Include 2 or more paths to compare")
4950

50-
path_stats = {path: Path(path).stat() for path in paths}
51+
path_stats = {}
52+
for path in paths:
53+
with suppress(FileNotFoundError):
54+
path_stats[path] = Path(path).stat()
5155

5256
sizes = [stat_res.st_size for stat_res in path_stats.values()]
5357
if not all(size == sizes[0] for size in sizes):
@@ -69,10 +73,12 @@ def sample_cmp(*paths, threads=1, gap=0.1, chunk_size=None, ignore_holes=False,
6973
path: pool.submit(sample_hash.sample_hash_file, path, threads=threads, gap=gap, chunk_size=chunk_size)
7074
for path in paths
7175
}
76+
7277
paths_dict = {}
7378
for path, future in futures.items():
74-
paths_dict[path] = future.result()
75-
79+
result = future.result()
80+
if result:
81+
paths_dict[path] = result
7682
sorted_paths = sorted(paths_dict.items(), key=lambda x: x[1])
7783
paths_str = "\n".join([f"{file_hash}\t{path}" for path, file_hash in sorted_paths])
7884

library/utils/web.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,9 @@ def get_title(args, url):
975975
for x in consts.COMMON_SITE_TITLE_SUFFIXES:
976976
title = title.replace(x, "")
977977

978-
log.info("[%s]: got title %s", url, title)
978+
title = strings.remove_consecutive_whitespace(title)
979979

980+
log.info("[%s]: got title %s", url, title)
980981
return title
981982

982983

0 commit comments

Comments
 (0)