Skip to content

Commit

Permalink
Fixed relative path problem with submit_job (NVIDIA#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvidianz authored Apr 23, 2022
1 parent cdaef9d commit 50e1699
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 3 additions & 9 deletions nvflare/fuel/hci/client/file_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from nvflare.fuel.hci.cmd_arg_utils import join_args
from nvflare.fuel.hci.reg import CommandModule, CommandModuleSpec, CommandSpec
from nvflare.fuel.hci.table import Table
from nvflare.fuel.hci.zip_utils import unzip_all_from_bytes, zip_directory_to_bytes
from nvflare.fuel.hci.zip_utils import remove_leading_dotdot, unzip_all_from_bytes, zip_directory_to_bytes

from .api_spec import AdminAPISpec, ReplyProcessor
from .api_status import APIStatus
Expand Down Expand Up @@ -139,12 +139,6 @@ def process_string(self, api, item: str):
)


def _remove_loading_dotdot(path):
while path.startswith("../"):
path = path[3:]
return path


class FileTransferModule(CommandModule):
"""Command module with commands relevant to file transfer."""

Expand Down Expand Up @@ -278,7 +272,7 @@ def upload_folder(self, args, api: AdminAPISpec):

# prepare for upload
rel_path = os.path.relpath(full_path, self.upload_dir)
folder_name = _remove_loading_dotdot(rel_path)
folder_name = remove_leading_dotdot(rel_path)

b64str = bytes_to_b64str(data)
parts = [_server_cmd_name(ftd.SERVER_CMD_UPLOAD_FOLDER), folder_name, b64str]
Expand Down Expand Up @@ -310,7 +304,7 @@ def submit_job(self, args, api: AdminAPISpec):
data = zip_directory_to_bytes(self.upload_dir, folder_name)

rel_path = os.path.relpath(full_path, self.upload_dir)
folder_name = _remove_loading_dotdot(rel_path)
folder_name = remove_leading_dotdot(rel_path)
b64str = bytes_to_b64str(data)
parts = [_server_cmd_name(ftd.SERVER_CMD_SUBMIT_JOB), folder_name, b64str]
command = join_args(parts)
Expand Down
8 changes: 7 additions & 1 deletion nvflare/fuel/hci/zip_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def _path_join(base: str, *parts: str) -> str:
return path.replace("\\", "/")


def remove_leading_dotdot(path):
while path.startswith("../"):
path = path[3:]
return path


def get_all_file_paths(directory):
"""Get all file paths in the directory.
Expand Down Expand Up @@ -77,7 +83,7 @@ def _zip_directory(root_dir: str, folder_name: str, writer):
with ZipFile(writer, "w") as z:
# writing each file one by one
for full_path in file_paths:
rel_path = os.path.relpath(full_path, root_dir)
rel_path = remove_leading_dotdot(os.path.relpath(full_path, root_dir))
z.write(full_path, arcname=rel_path)


Expand Down

0 comments on commit 50e1699

Please sign in to comment.