fix(scripts): detect container vs host layout reliably in reset_admin_password
Replace heuristic directory scan with explicit container detection: /app/scripts path means container, script sibling to api/ means host. Prevents accidental /app/data/api misdetection when that dir exists. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,19 +12,15 @@ import secrets
|
|||||||
import string
|
import string
|
||||||
|
|
||||||
_here = os.path.dirname(os.path.abspath(__file__))
|
_here = os.path.dirname(os.path.abspath(__file__))
|
||||||
# Find auth_manager: host layout has api/ sibling, container has it one level up at /app
|
# In container the script lives at /app/scripts/; on host at <repo>/scripts/
|
||||||
for _api_path in [os.path.join(_here, '..', 'api'), os.path.join(_here, '..'), '/app']:
|
_in_container = os.path.abspath(_here) == '/app/scripts'
|
||||||
if os.path.isfile(os.path.join(_api_path, 'auth_manager.py')):
|
|
||||||
sys.path.insert(0, os.path.normpath(_api_path))
|
|
||||||
break
|
|
||||||
|
|
||||||
ROOT = os.path.normpath(os.path.join(_here, '..'))
|
if _in_container:
|
||||||
# data dir: host uses ROOT/data/api, container mounts data/api at ROOT/data
|
sys.path.insert(0, '/app')
|
||||||
for _data in [os.path.join(ROOT, 'data', 'api'), os.path.join(ROOT, 'data'), '/app/data']:
|
_DATA_DIR = '/app/data'
|
||||||
if os.path.isdir(_data):
|
|
||||||
_DATA_DIR = _data
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
|
ROOT = os.path.normpath(os.path.join(_here, '..'))
|
||||||
|
sys.path.insert(0, os.path.join(ROOT, 'api'))
|
||||||
_DATA_DIR = os.path.join(ROOT, 'data', 'api')
|
_DATA_DIR = os.path.join(ROOT, 'data', 'api')
|
||||||
|
|
||||||
INIT_PW_FILE = os.path.join(_DATA_DIR, '.admin_initial_password')
|
INIT_PW_FILE = os.path.join(_DATA_DIR, '.admin_initial_password')
|
||||||
|
|||||||
Reference in New Issue
Block a user