Skip to content

Commit

Permalink
Version/restore tale data dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarthisius committed Feb 7, 2022
1 parent de0a4bb commit 96a1970
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions server/resources/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def restore(self, tale: dict, version: dict):
shutil.rmtree(workspace_path)
workspace_path.mkdir()
self._snapshotRecursive(None, version_workspace_path, workspace_path)
# restore data dir
self._restoreDataDir(tale, version, user=user)
# restore Tale
tale.update(self._restoreTaleFromVersion(version))
return Tale().save(tale)
Expand Down Expand Up @@ -439,6 +441,41 @@ def snapshot(
newWorkspace = new_version_path / 'workspace'
newWorkspace.mkdir()
self._snapshotRecursive(oldWorkspace, crtWorkspace, newWorkspace)
self._snapshotDataDir(tale, new_version, user=user)

@staticmethod
def _snapshotDataDir(tale, version, user=None):
data_dir = Folder().load(tale["dataDirId"], user=user, level=AccessType.READ)
current_data_dir = Folder().childFolders(
data_dir, "folder", user=user, filters={"name": "current"}
)[0]

Folder().copyFolder(
current_data_dir,
parent=data_dir,
name=str(version["_id"]),
parentType="folder",
creator=user,
)

@staticmethod
def _restoreDataDir(tale, version, user=None):
data_dir = Folder().load(tale["dataDirId"], user=user, level=AccessType.READ)
current_data_dir = Folder().childFolders(
data_dir, "folder", user=user, filters={"name": "current"}
)[0]
source_data_dir = Folder().childFolders(
data_dir, "folder", user=user, filters={"name": str(version["_id"])}
)[0]

Folder().clean(current_data_dir)
Folder().copyFolderComponents(
source_data_dir,
current_data_dir,
user,
None,
current_data_dir
)

def _is_same(self, tale, version, user):
workspace = Folder().load(tale["workspaceId"], force=True)
Expand Down

0 comments on commit 96a1970

Please sign in to comment.