Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ignite/handlers/checkpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections.abc as collections
import numbers
import os
import stat
import tempfile
import warnings
from abc import ABCMeta, abstractmethod
Expand Down Expand Up @@ -708,7 +709,9 @@ def _save_func(self, checkpoint: Mapping, path: str, func: Callable, rank: int =
else:
if tmp is not None:
tmp.close()
os.rename(tmp.name, path)
os.replace(tmp.name, path)
# append group/others read mode
os.chmod(path, os.stat(path).st_mode | stat.S_IRGRP | stat.S_IROTH)

@idist.one_rank_only()
def remove(self, filename: str) -> None:
Expand Down
7 changes: 7 additions & 0 deletions tests/ignite/handlers/test_checkpoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import stat
import warnings
from collections import OrderedDict
from unittest.mock import MagicMock
Expand Down Expand Up @@ -581,6 +582,12 @@ def _test_existance(atomic, _to_save, expected):
pass
fp = os.path.join(saver.dirname, fname)
assert os.path.exists(fp) == expected

if expected:
# related to https://github.com/pytorch/ignite/issues/1876
mode = stat.filemode(os.stat(fp).st_mode)
assert [mode[1], mode[4], mode[7]] == ["r", "r", "r"], mode

if expected:
saver.remove(fname)

Expand Down