Skip to content

Commit d2e350b

Browse files
committed
出力先ディレクトリが既に存在しても無視する
手動でディレクトリが存在しなかったら作るという判定を行っているが、並列 で実行している場合には、ディレクトリの存在チェック (os.path.exists) と 実際のディレクトリの作成 (os.makedirs) の間に、他のスレッドがディレク トリを作成してしまいエラーが生じる可能性が残る (race condition)。始め から os.makedirs の側で既に存在するディレクトリを無視するべき。 cpprefjp/site#1478 (comment)
1 parent a5ea672 commit d2e350b

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ def convert(path, template, context, hrefs, global_qualify_list, global_defined_
147147

148148
context['mathjax'] = info['mathjax_enabled']
149149
dst_dir = os.path.dirname(os.path.join(settings.OUTPUT_DIR, path))
150-
if not os.path.exists(dst_dir):
151-
os.makedirs(dst_dir)
150+
os.makedirs(dst_dir, exist_ok=True)
152151
html_data = template.render(body=body, **context)
153152
if settings.USE_MINIFY:
154153
import htmlmin

0 commit comments

Comments
 (0)