Skip to content

Commit bb08c7b

Browse files
refactor: Move "or []" fixes to their own line
1 parent 3981df2 commit bb08c7b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ctfcli/core/challenge.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ def _load_challenge_id(self):
251251
raise RemoteChallengeNotFound(f"Could not load remote challenge with name '{self['name']}'")
252252

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

@@ -364,7 +364,9 @@ def _create_file(self, local_path: Path):
364364

365365
def _create_all_files(self):
366366
new_files = []
367-
for challenge_file in self.get("files") or []:
367+
368+
files = self.get("files") or []
369+
for challenge_file in files:
368370
new_files.append(("file", open(self.challenge_directory / challenge_file, mode="rb")))
369371

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

588590
# Create / Upload files
589591
if "files" not in ignore:
592+
self["files"] = self.get("files") or []
593+
remote_challenge["files"] = remote_challenge.get("files") or []
594+
590595
# Get basenames of local files to compare against remote files
591-
local_files = {f.split("/")[-1]: f for f in self.get("files") or []}
592-
remote_files = self._normalize_remote_files(remote_challenge.get("files") or [])
596+
local_files = {f.split("/")[-1]: f for f in self["files"]}
597+
remote_files = self._normalize_remote_files(remote_challenge["files"])
593598

594599
# Delete remote files which are no longer defined locally
595600
for remote_file in remote_files:

0 commit comments

Comments
 (0)