Skip to content

Commit

Permalink
Merge pull request #8 from neuro-ml/dev
Browse files Browse the repository at this point in the history
Better temp folder for cache index
  • Loading branch information
maxme1 authored Jul 18, 2022
2 parents 1103755 + 622fe57 commit ae59680
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tarn/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = '0.1.1'
16 changes: 7 additions & 9 deletions tarn/cache/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import shutil
import tempfile
import warnings
from itertools import chain
from pathlib import Path
Expand All @@ -18,7 +19,6 @@
logger = logging.getLogger(__name__)

DATA_FOLDER = 'data'
TEMP_FOLDER = 'temp'
HASH_FILENAME = 'hash.bin'
GZIP_COMPRESSION = 1

Expand All @@ -36,13 +36,13 @@ def _check_folder_consistency(self, base: Path, key: Key, folder: Path, context)
match_files(base / HASH_FILENAME, folder / HASH_FILENAME)

def _write(self, base: Path, key: Key, value: Any, context: Any):
data_folder, temp_folder = base / DATA_FOLDER, base / TEMP_FOLDER
create_folders(data_folder, self.permissions, self.group)
create_folders(temp_folder, self.permissions, self.group)
with tempfile.TemporaryDirectory() as temp_folder:
data_folder, temp_folder = base / DATA_FOLDER, Path(temp_folder)
create_folders(data_folder, self.permissions, self.group)

self.serializer.save(value, temp_folder)
self._mirror_to_storage(temp_folder, data_folder)
self._save_meta(base, context)
self.serializer.save(value, temp_folder)
self._mirror_to_storage(temp_folder, data_folder)
self._save_meta(base, context)

def _replicate(self, base: Path, key: Key, source: Path, context):
# data
Expand Down Expand Up @@ -112,8 +112,6 @@ def _mirror_to_storage(self, source: Path, destination: Path):
os.remove(file)
to_read_only(target, self.permissions, self.group)

shutil.rmtree(source)

def _cleanup_corrupted(self, folder, digest):
message = f'Corrupted storage at {self.root} for key {digest}. Cleaning up.'
warnings.warn(message, RuntimeWarning)
Expand Down

0 comments on commit ae59680

Please sign in to comment.