somratpro commited on
Commit
fdc1270
·
1 Parent(s): 79e2809

Fix: Exclude SQLite temp files from sync, improve Cloudflare error diagnostics

Browse files
Files changed (2) hide show
  1. cloudflare-keepalive-setup.py +12 -2
  2. hermes-sync.py +9 -1
cloudflare-keepalive-setup.py CHANGED
@@ -9,6 +9,7 @@ import re
9
  import sys
10
  import time
11
  import urllib.request
 
12
  from pathlib import Path
13
 
14
  API_BASE = "https://api.cloudflare.com/client/v4"
@@ -22,8 +23,17 @@ def cf_request(method: str, path: str, token: str, body: bytes | None = None, co
22
  method=method,
23
  headers={"Authorization": f"Bearer {token}", "Content-Type": content_type},
24
  )
25
- with urllib.request.urlopen(req, timeout=30) as response:
26
- payload = json.loads(response.read().decode("utf-8"))
 
 
 
 
 
 
 
 
 
27
  if not payload.get("success"):
28
  errors = payload.get("errors") or [{"message": "Unknown Cloudflare API error"}]
29
  raise RuntimeError(errors[0].get("message", "Unknown Cloudflare API error"))
 
9
  import sys
10
  import time
11
  import urllib.request
12
+ import urllib.error
13
  from pathlib import Path
14
 
15
  API_BASE = "https://api.cloudflare.com/client/v4"
 
23
  method=method,
24
  headers={"Authorization": f"Bearer {token}", "Content-Type": content_type},
25
  )
26
+ try:
27
+ with urllib.request.urlopen(req, timeout=30) as response:
28
+ payload = json.loads(response.read().decode("utf-8"))
29
+ except urllib.error.HTTPError as e:
30
+ try:
31
+ error_body = json.loads(e.read().decode("utf-8"))
32
+ errors = error_body.get("errors") or [{"message": "Unknown error"}]
33
+ error_msg = errors[0].get("message", "Unknown error") if errors else "Unknown error"
34
+ except:
35
+ error_msg = f"HTTP {e.code}: {e.reason}"
36
+ raise RuntimeError(f"Cloudflare API {e.code}: {error_msg}")
37
  if not payload.get("success"):
38
  errors = payload.get("errors") or [{"message": "Unknown Cloudflare API error"}]
39
  raise RuntimeError(errors[0].get("message", "Unknown Cloudflare API error"))
hermes-sync.py CHANGED
@@ -96,7 +96,11 @@ def should_exclude(rel_posix: str, path: Path) -> bool:
96
  return True
97
  if any(part in EXCLUDED_DIRS for part in parts):
98
  return True
 
99
  if path.is_file():
 
 
 
100
  try:
101
  return path.stat().st_size > MAX_FILE_SIZE_BYTES
102
  except OSError:
@@ -153,7 +157,11 @@ def create_snapshot_dir(source_root: Path) -> Path:
153
  target.mkdir(parents=True, exist_ok=True)
154
  continue
155
  target.parent.mkdir(parents=True, exist_ok=True)
156
- shutil.copy2(path, target)
 
 
 
 
157
  return staging_root
158
 
159
 
 
96
  return True
97
  if any(part in EXCLUDED_DIRS for part in parts):
98
  return True
99
+ # Exclude SQLite temporary files (shm, wal, journal)
100
  if path.is_file():
101
+ name_lower = path.name.lower()
102
+ if name_lower.endswith((".db-shm", ".db-wal", ".db-journal")):
103
+ return True
104
  try:
105
  return path.stat().st_size > MAX_FILE_SIZE_BYTES
106
  except OSError:
 
157
  target.mkdir(parents=True, exist_ok=True)
158
  continue
159
  target.parent.mkdir(parents=True, exist_ok=True)
160
+ try:
161
+ shutil.copy2(path, target)
162
+ except OSError:
163
+ # File may have been deleted by the application since enumeration
164
+ continue
165
  return staging_root
166
 
167