t Qwen-Coder commited on
Commit
e4073b4
·
1 Parent(s): 7d3748e

Fix database locking issue during HF sync\n\n- Removed shutil.move() that was temporarily replacing the active database file\n- Now upload the backup file directly without affecting the active database\n- This prevents 'attempt to write a readonly database' errors during sync operations\n- Ensures database remains accessible for writes during backup process

Browse files
Files changed (1) hide show
  1. hf_sync.py +4 -3
hf_sync.py CHANGED
@@ -67,11 +67,12 @@ def upload():
67
  db_hash = get_file_hash(backup_path)
68
  if db_hash != state.get("last_db_hash"):
69
  print("Syncing Database...")
70
- shutil.move(backup_path, DB_FILE)
71
- api.upload_file(path_or_fileobj=DB_FILE, path_in_repo="database.db", repo_id=REPO_ID, repo_type="dataset")
72
  state["last_db_hash"] = db_hash
73
  changes_made = True
74
- else:
 
75
  os.remove(backup_path)
76
 
77
  # 2. Sync Files Iteratively (Immune to folder timeouts)
 
67
  db_hash = get_file_hash(backup_path)
68
  if db_hash != state.get("last_db_hash"):
69
  print("Syncing Database...")
70
+ # Upload the backup file directly without replacing the active database
71
+ api.upload_file(path_or_fileobj=backup_path, path_in_repo="database.db", repo_id=REPO_ID, repo_type="dataset")
72
  state["last_db_hash"] = db_hash
73
  changes_made = True
74
+ # Clean up the backup file regardless
75
+ if os.path.exists(backup_path):
76
  os.remove(backup_path)
77
 
78
  # 2. Sync Files Iteratively (Immune to folder timeouts)