Skip to content

Commit

Permalink
Merge pull request #572 from JrGoodle/move-clowder-dir
Browse files Browse the repository at this point in the history
Fix handling of broken symlink
  • Loading branch information
JrGoodle committed Jun 18, 2020
2 parents 475c40c + 142fad0 commit b472b9c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/clowder/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _set_clowder_yaml(self, yaml_file: Path) -> None:

# Broken symlink pointing to missing source
if yaml_file.is_symlink() and not yaml_file.exists():
message = fmt.error_clowder_symlink_source_missing(yaml_file, self.clowder_dir)
message = fmt.error_clowder_symlink_source_missing(yaml_file)
self.clowder_yaml_missing_source_error = ClowderError(ClowderErrorType.CLOWDER_SYMLINK_SOURCE_MISSING,
message)
return
Expand Down
9 changes: 4 additions & 5 deletions src/clowder/util/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,17 @@ def error_clowder_already_initialized() -> str:
return f"{ERROR} Clowder already initialized in this directory"


def error_clowder_symlink_source_missing(symlink_path: Path, clowder_dir: Path) -> str:
def error_clowder_symlink_source_missing(symlink_path: Path) -> str:
"""Return formatted error string for clowder symlink source not found
:param Path symlink_path: Clowder yaml symlink path
:param Path clowder_dir: Clowder directory
:return: Formatted clowder symlink source not found warning
:rtype: str
"""

target = _yaml_file(symlink_path.relative_to(clowder_dir))
source = _yaml_file(symlink_path.resolve().relative_to(clowder_dir))
return f"{ERROR} Found symink {target} -> {source} but source appears to be missing"
target = _yaml_file(str(symlink_path))
source = _yaml_file(str(symlink_path.resolve()))
return f"{ERROR} Found symink {target} but source {source} appears to be missing"


def error_command_failed(cmd: Union[str, List[str]]) -> str:
Expand Down
26 changes: 26 additions & 0 deletions test/scripts/cats/clowder-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ echo "TEST: Test clowder commands with various states of clowder repo dir and cl

cd "$CATS_EXAMPLE_DIR" || exit 1

test_move_clowder_repo() {
print_single_separator
echo "TEST: "
./clean.sh
./init.sh || exit 1
begin_command
$COMMAND herd $PARALLEL || exit 1
end_command
cd '..' || exit 1
mv 'cats' 'cats-moved' || exit 1
cd 'cats-moved' || exit 1
begin_command
$COMMAND herd $PARALLEL && exit 1
end_command
begin_command
$COMMAND link || exit 1
end_command
begin_command
$COMMAND herd $PARALLEL || exit 1
end_command
cd '..' || exit 1
mv 'cats-moved' 'cats' || exit 1
cd 'cats' || exit 1
}
test_move_clowder_repo

test_commands_with_yaml_file_no_clowder_repo() {
print_single_separator
echo "TEST: Run commands with clowder.yaml file that is not a symlink and no existing .clowder directory"
Expand Down

0 comments on commit b472b9c

Please sign in to comment.