Skip to content

Commit

Permalink
Set permissions for transaction files to 0o666
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Jan 20, 2025
1 parent 5ece8ad commit 1528d2e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ert/storage/local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ def _write_transaction(self, filename: str | os.PathLike[str], data: bytes) -> N
self._swap_path.mkdir(parents=True, exist_ok=True)
with NamedTemporaryFile(dir=self._swap_path, delete=False) as f:
f.write(data)
os.chmod(f.name, 0o666)
os.rename(f.name, filename)

def _to_netcdf_transaction(
Expand All @@ -570,6 +571,7 @@ def _to_netcdf_transaction(
self._swap_path.mkdir(parents=True, exist_ok=True)
with NamedTemporaryFile(dir=self._swap_path, delete=False) as f:
dataset.to_netcdf(f, engine="scipy")
os.chmod(f.name, 0o666)
os.rename(f.name, filename)

def _to_parquet_transaction(
Expand All @@ -584,6 +586,7 @@ def _to_parquet_transaction(
self._swap_path.mkdir(parents=True, exist_ok=True)
with NamedTemporaryFile(dir=self._swap_path, delete=False) as f:
dataframe.write_parquet(f.name)
os.chmod(f.name, 0o666)
os.rename(f.name, filename)


Expand Down
1 change: 1 addition & 0 deletions src/ert/storage/migration/to9.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def _write_transaction(filename: str | os.PathLike[str], data: bytes) -> None:
Path("./swp").mkdir(parents=True, exist_ok=True)
with NamedTemporaryFile(dir="./swp", delete=False) as f:
f.write(data)
os.chmod(f.name, 0o666)
os.rename(f.name, filename)


Expand Down
2 changes: 2 additions & 0 deletions tests/ert/unit_tests/storage/test_local_storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import shutil
import stat
import tempfile
from dataclasses import dataclass, field
from datetime import datetime, timedelta
Expand Down Expand Up @@ -585,6 +586,7 @@ def test_write_transaction(data):
filepath = Path("./file.txt")
storage._write_transaction(filepath, data)

assert stat.S_IMODE(filepath.stat().st_mode) == 0o666
assert filepath.read_bytes() == data


Expand Down

0 comments on commit 1528d2e

Please sign in to comment.