Skip to content
Snippets Groups Projects
Commit 45b4f6da authored by Andrei Plamada's avatar Andrei Plamada
Browse files

first draft symlinks

parent db01a243
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ datastore_server/source/core-plugins ...@@ -8,6 +8,7 @@ datastore_server/source/core-plugins
openbis/source/core-plugins openbis/source/core-plugins
*/bin/* */bin/*
**/.DS_Store **/.DS_Store
*__pycache__/
*$py.class *$py.class
**/.pydevproject **/.pydevproject
**/.shredder **/.shredder
......
...@@ -162,6 +162,9 @@ class DataSet( ...@@ -162,6 +162,9 @@ class DataSet(
return self.data['physicalData']['status'] return self.data['physicalData']['status']
except Exception: except Exception:
return None return None
@property
def sftp_path(self):
return os.path(self.experiment.identifier[1:], self.permId)
def archive(self, remove_from_data_store=True): def archive(self, remove_from_data_store=True):
fetchopts = { fetchopts = {
......
...@@ -255,3 +255,47 @@ def extract_userId(user): ...@@ -255,3 +255,47 @@ def extract_userId(user):
return str(user) return str(user)
def check_symlink(target_dir: str) -> Path:
# there are several options: basically resolvable symlink, non-resolvable symlink, does not exist at all or exists but it is not a symlink
target_dir_path = Path(target_dir)
if target_dir_path.is_symlink() and target_dir_path.exists():
return target_dir_path.resolve()
elif target_dir_path.is_symlink() and not target_dir_path.exists():
raise FileNotFoundError(
f"target_dir={target_dir} is non-resolvable symlink. No such file or directory: {target_dir_path.resolve()}"
)
elif not target_dir_path.is_symlink() and not target_dir_path.exists():
raise FileNotFoundError(f"target_dir={target_dir} does not exist")
else:
raise ValueError(f"target_dir={target_dir} exists but it is not a symlink")
def create_symlink(
target_dir: str, source_dir: str, mountpoint: str, replace_if_symlink: bool = True
):
# Path(mountpoint,ds.experiment.identifier[1:],ds.permId)
# replace_if_symlink will replace the the target_dir in case it is an existing symlink
mountpoint_path = Path(mountpoint)
# check mountpoint
if not mountpoint_path.is_mount():
if not mountpoint_path.exists():
raise FileNotFoundError(f"mountpoint={mountpoint} does not exist")
else:
raise ValueError(f"mountpoint={mountpoint} exists but it is not a mount")
# join mountpoint and source_dir
# if source_dir is absolute we have to remove "/" to be able to join it with mountpoint
# I did not find any way to achieve this in case they are pathlib.Path
if source_dir[0] == "/":
source_dir = source_dir[1:]
source_dir_path = Path(mountpoint, source_dir)
target_dir_path = Path(target_dir)
if target_dir_path.is_symlink() and replace_if_symlink:
target_dir_path.unlink()
target_dir_path.symlink_to(source_dir_path, target_is_directory=True)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment