Skip to content

Commit

Permalink
cli: report in case input directories are listed under files
Browse files Browse the repository at this point in the history
  • Loading branch information
audrium committed Nov 14, 2022
1 parent d3c26c4 commit 7cc1c51
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Version 0.9.0 (UNRELEASED)
- Fixes ``validate --environment`` command to detect illegal white space characters in image names.
- Fixes ``list`` command to highlight the workflow specified in ``REANA_WORKON`` correctly.
- Fixes ``secrets-delete`` command error message when deleting non existing secrets.
- Fixes ``upload`` command to report in case input directories are listed under files and vice versa.

Version 0.8.2 (UNRELEASED)
--------------------------
Expand Down
34 changes: 29 additions & 5 deletions reana_client/cli/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,29 @@ def upload_files( # noqa: C901

if reana_spec.get("inputs"):
filenames = []
filenames += [
os.path.join(os.getcwd(), f)
for f in reana_spec["inputs"].get("files") or []
]

# collect all files in input.files
for f in reana_spec["inputs"].get("files") or []:
# check for directories in files
if os.path.isdir(f):
display_message(
f"Found directory in `inputs.files`: {f}",
msg_type="error",
)
sys.exit(1)
filenames.append(os.path.join(os.getcwd(), f))

# collect all files in input.directories
files_from_directories = []
directories = reana_spec["inputs"].get("directories") or []
for directory_path in directories:
# check for files in directories
if os.path.isfile(directory_path):
display_message(
f"Found file in `inputs.directories`: {directory_path}",
msg_type="error",
)
sys.exit(1)
for root, _, dir_filenames in os.walk(directory_path):
filenames_full_path = [
os.path.join(root, file) for file in dir_filenames
Expand Down Expand Up @@ -402,8 +416,18 @@ def _filter_files(
filenames += [
os.path.join(os.getcwd(), file) for file in files_from_directories
]

# collect and filter out all the unique filepaths
filepaths = set()
for filepath in filenames:
if os.path.isfile(filepath):
filepaths.add(filepath)
else:
for root, _, files in os.walk(filepath):
filepaths.update([os.path.join(root, file) for file in files])

upload_failed = False
for filename in filenames:
for filename in filepaths:
try:
if not is_regular_path(filename):
display_message(f"Ignoring symlink {filepath}", msg_type="info")
Expand Down

0 comments on commit 7cc1c51

Please sign in to comment.