wu981526092 commited on
Commit
d9fe982
·
1 Parent(s): 26d8ef2

🔧 Fix '/logs' permission denied error in HF Spaces

Browse files

✅ Problem solved:
• Fixed PROJECT_ROOT calculation in server_config.py
• Fixed LOG_DIR calculation in backend/database/init_db.py
• Removed extra .parent that was causing paths to point to wrong directory

🎯 Root cause:
• PROJECT_ROOT was calculated as parent.parent.parent instead of parent.parent
• This caused logs path to point to root directory /logs in HF Docker
• HF Spaces non-root user doesn't have permission to create /logs

⚡ Fix:
• backend/server_config.py: PROJECT_ROOT = parent.parent (correct)
• backend/database/init_db.py: Added extra dirname() for correct path
• Now all paths point to application directory, not system root

🚀 Result: Application should start successfully in HF Spaces

backend/database/init_db.py CHANGED
@@ -15,8 +15,8 @@ import logging
15
  import shutil
16
  import time
17
 
18
- # Configure logging
19
- LOG_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "logs")
20
  os.makedirs(LOG_DIR, exist_ok=True)
21
 
22
  logging.basicConfig(
 
15
  import shutil
16
  import time
17
 
18
+ # Configure logging (backend/database/init_db.py -> backend/database/ -> backend/ -> project_root/ -> logs/)
19
+ LOG_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "logs")
20
  os.makedirs(LOG_DIR, exist_ok=True)
21
 
22
  logging.basicConfig(
backend/server_config.py CHANGED
@@ -13,8 +13,8 @@ SERVER_VERSION = "1.2.0"
13
  MAX_PORT_ATTEMPTS = 50
14
  LOG_LEVEL = "INFO"
15
 
16
- # Get the project root directory
17
- PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
18
 
19
  # Paths (using absolute paths relative to project root)
20
  PROCESSING_STATUS_FILE = str(PROJECT_ROOT / "logs" / "processing_status.json")
 
13
  MAX_PORT_ATTEMPTS = 50
14
  LOG_LEVEL = "INFO"
15
 
16
+ # Get the project root directory (backend/server_config.py -> backend/ -> project_root/)
17
+ PROJECT_ROOT = Path(__file__).resolve().parent.parent
18
 
19
  # Paths (using absolute paths relative to project root)
20
  PROCESSING_STATUS_FILE = str(PROJECT_ROOT / "logs" / "processing_status.json")