Skip to content

Commit 16509cb

Browse files
committed
fix: preserve file permissions on atomic registry save
Capture existing registry file mode before replace and apply it to the temp file via os.chmod, so mkstemp's 0o600 default doesn't change on-disk permissions.
1 parent 15beca8 commit 16509cb

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/specify_cli/workflows/catalog.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,26 @@ def _load(self) -> dict[str, Any]:
9191
def save(self) -> None:
9292
"""Persist registry to disk atomically (write to temp, then rename)."""
9393
self.workflows_dir.mkdir(parents=True, exist_ok=True)
94+
95+
# Capture existing file permissions to preserve after replace
96+
existing_stat = None
97+
if self.registry_path.exists():
98+
try:
99+
existing_stat = self.registry_path.stat()
100+
except OSError:
101+
pass
102+
94103
fd, tmp_path = tempfile.mkstemp(
95104
suffix=".json", dir=self.workflows_dir
96105
)
97106
try:
98107
with os.fdopen(fd, "w", encoding="utf-8") as f:
99108
json.dump(self.data, f, indent=2)
109+
if existing_stat is not None:
110+
try:
111+
os.chmod(tmp_path, existing_stat.st_mode & 0o7777)
112+
except OSError:
113+
pass
100114
os.replace(tmp_path, self.registry_path)
101115
except BaseException:
102116
try:

0 commit comments

Comments
 (0)