From 98399ecf75d89b788e47232493a789dc0cf2e1a6 Mon Sep 17 00:00:00 2001 From: Abdul Aouwal <58025118+aouwalitshikkha@users.noreply.github.com> Date: Sat, 20 Jun 2026 22:05:20 +0600 Subject: [PATCH] fix: ensure data directory exists before init_db call sqlite3.connect() fails with 'unable to open database file' on fresh installs where data/ directory does not exist. This happens with both Docker (bind mount creates ./data as root, container user can't write) and bare Python (no data/ directory at all). Fix ensures data/ exists before any database operation: - main.py: add os.makedirs before init_db() call - start-librecrawl.sh: mkdir -p data at script start - start-librecrawl.bat: mkdir data at script start Fixes #65 --- main.py | 3 +++ start-librecrawl.bat | 1 + start-librecrawl.sh | 1 + 3 files changed, 5 insertions(+) diff --git a/main.py b/main.py index 57c9b8e..2d2a717 100644 --- a/main.py +++ b/main.py @@ -54,6 +54,9 @@ # Enable compression for all responses Compress(app) +# Ensure data directory exists before initializing the database +os.makedirs("data", exist_ok=True) + # Initialize database on startup init_db() diff --git a/start-librecrawl.bat b/start-librecrawl.bat index bf2621b..9a9e0d6 100644 --- a/start-librecrawl.bat +++ b/start-librecrawl.bat @@ -1,5 +1,6 @@ @echo off +if not exist data mkdir data echo Checking for Docker... docker --version 2>nul if errorlevel 1 goto nodocker diff --git a/start-librecrawl.sh b/start-librecrawl.sh index 7c9a979..dbfbac9 100644 --- a/start-librecrawl.sh +++ b/start-librecrawl.sh @@ -2,6 +2,7 @@ # Start LibreCrawl - tries Docker first, falls back to Python +mkdir -p data echo "Checking for Docker..." if command -v docker &> /dev/null && command -v docker compose &> /dev/null; then echo "Docker found! Starting LibreCrawl with Docker..."