Skip to content

Commit

Permalink
refactor: Move "or []" fixes to their own line
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeine-addictt committed Dec 29, 2024
1 parent 3981df2 commit bb08c7b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ctfcli/core/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ def _load_challenge_id(self):
raise RemoteChallengeNotFound(f"Could not load remote challenge with name '{self['name']}'")

def _validate_files(self):
# if the challenge defines files, make sure they exist before making any changes to the challenge
for challenge_file in self.get("files") or []:
files = self.get("files") or []
for challenge_file in files:
if not (self.challenge_directory / challenge_file).exists():
raise InvalidChallengeFile(f"File {challenge_file} could not be loaded")

Expand Down Expand Up @@ -364,7 +364,9 @@ def _create_file(self, local_path: Path):

def _create_all_files(self):
new_files = []
for challenge_file in self.get("files") or []:

files = self.get("files") or []
for challenge_file in files:
new_files.append(("file", open(self.challenge_directory / challenge_file, mode="rb")))

files_payload = {"challenge_id": self.challenge_id, "type": "challenge"}
Expand Down Expand Up @@ -587,9 +589,12 @@ def sync(self, ignore: Tuple[str] = ()) -> None:

# Create / Upload files
if "files" not in ignore:
self["files"] = self.get("files") or []
remote_challenge["files"] = remote_challenge.get("files") or []

# Get basenames of local files to compare against remote files
local_files = {f.split("/")[-1]: f for f in self.get("files") or []}
remote_files = self._normalize_remote_files(remote_challenge.get("files") or [])
local_files = {f.split("/")[-1]: f for f in self["files"]}
remote_files = self._normalize_remote_files(remote_challenge["files"])

# Delete remote files which are no longer defined locally
for remote_file in remote_files:
Expand Down

0 comments on commit bb08c7b

Please sign in to comment.