Skip to content

Commit

Permalink
Properly load index.json before migrating
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkwah committed Sep 1, 2023
1 parent e178a03 commit 3df5ab7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/ert/storage/local_storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import json
import logging
import os
import sys
Expand Down Expand Up @@ -172,7 +171,8 @@ def __init__(
self.path = Path(path)
if not ignore_migration_check:
try:
version = _storage_version(self.path)
self._index = _storage_index(self.path)
version = self._index.version
if version == 0:
from ert.storage.migration import block_fs # pylint: disable=C0415

Expand Down Expand Up @@ -290,17 +290,16 @@ def _load_ensemble(self, path: Path) -> LocalEnsembleAccessor:
return LocalEnsembleAccessor(self, path)


def _storage_version(path: Path) -> Optional[int]:
def _storage_index(path: Path) -> _Index:
if not path.exists():
return None
return _Index()
try:
with open(path / "index.json", encoding="utf-8") as f:
return int(json.load(f)["version"])
return _Index.parse_file(path / "index.json")
except KeyError as exc:
raise NotImplementedError("Incompatible ERT Local Storage") from exc
except FileNotFoundError:
if _is_block_storage(path):
return 0
return _Index(version=0)
raise ValueError("Unknown storage version")


Expand Down

0 comments on commit 3df5ab7

Please sign in to comment.