From 3817a359a40a85c006075eeebbfc525f9d93182d Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Date: Fri, 6 Jun 2025 08:54:45 +0200 Subject: [PATCH] Fix path handling when there are no repositories --- api/repo_api.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/api/repo_api.py b/api/repo_api.py index 6e00356..5e4cdaa 100644 --- a/api/repo_api.py +++ b/api/repo_api.py @@ -2309,13 +2309,17 @@ def git_list_repositories(): return jsonify({"error": "Repository storage not found, git functionality may not be installed."}), 500 repos = [] - for entry in os.scandir(os.path.join(REPOSITORIES_BASE_PATH, OGGIT_USER)): - if entry.is_dir(follow_symlinks=False) and os.path.isfile(os.path.join(entry.path, "HEAD")): - name = entry.name - if name.endswith(".git"): - name = name[:-4] + if os.path.exists(os.path.join(REPOSITORIES_BASE_PATH, OGGIT_USER)): + # If the base path exists, but the OGGIT_USER subpath doesn't, it means we've got an empty + # install. OgGit is present, but there's no repos yet. - repos = repos + [name] + for entry in os.scandir(os.path.join(REPOSITORIES_BASE_PATH, OGGIT_USER)): + if entry.is_dir(follow_symlinks=False) and os.path.isfile(os.path.join(entry.path, "HEAD")): + name = entry.name + if name.endswith(".git"): + name = name[:-4] + + repos = repos + [name] journal.send(f"Returning {len(repos)} repositories", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")