fix: handle list response when checking file existence
This commit is contained in:
parent
c5c5e8bbfd
commit
183959f4a0
@ -98,8 +98,15 @@ def main() -> int:
|
|||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(get_req) as resp:
|
with urllib.request.urlopen(get_req) as resp:
|
||||||
existing_file = json.loads(resp.read().decode())
|
existing_file = json.loads(resp.read().decode())
|
||||||
sha = existing_file.get("sha")
|
# API may return a list (directory contents) or dict (single file)
|
||||||
print(f"File exists, updating (sha: {sha})")
|
if isinstance(existing_file, dict):
|
||||||
|
sha = existing_file.get("sha")
|
||||||
|
print(f"File exists, updating (sha: {sha})")
|
||||||
|
elif isinstance(existing_file, list):
|
||||||
|
# Response is a directory listing, file doesn't exist at this exact path
|
||||||
|
print(f"Path is a directory or file not found in expected format")
|
||||||
|
else:
|
||||||
|
print(f"Unexpected response type: {type(existing_file)}")
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
if e.code != 404:
|
if e.code != 404:
|
||||||
print(f"Error checking file existence: {e}", file=sys.stderr)
|
print(f"Error checking file existence: {e}", file=sys.stderr)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user