--- a/access/access.go Wed Apr 12 23:21:11 2023 -0500
+++ b/access/access.go Wed Apr 12 23:40:09 2023 -0500
@@ -23,6 +23,8 @@
+ repositories map[string]string func Setup(repositoriesPath, adminRepo string) error {
@@ -80,6 +82,10 @@
+ if err := refreshRepositories(); err != nil { if err := refreshHgWeb(); err != nil {
--- a/access/hgweb.go Wed Apr 12 23:21:11 2023 -0500
+++ b/access/hgweb.go Wed Apr 12 23:40:09 2023 -0500
@@ -3,9 +3,6 @@
func refreshHgWeb() error {
@@ -17,37 +14,13 @@
fmt.Fprintf(fp, "[paths]\n")
- absReposPath, err := filepath.Abs(ReposPath())
- // walk the reposPath, looking for .hg directories, when one is found,
- // check if it is publicly readable, and if so, add it to the config file.
- filepath.WalkDir(absReposPath, func(filename string, entry os.DirEntry, err error) error {
- // check if we're looking at a directory
+ for relativeRepoPath, repoPath := range repositories { + rootedPath := "/" + relativeRepoPath + // check if it's publicly readable + if CanRead("public", rootedPath) { + fmt.Fprintf(fp, "%s = %s\n", rootedPath, repoPath)
- // check if it is a .hg directory
- if !strings.HasSuffix(entry.Name(), ".hg") {
- // figure out the repo path that we will be checking against the casbin
- // stuff. That means it needs to be the exact path of the repo and not
- // include the parent directory.
- repoPath := path.Dir(filename)
- relativeRepoPath := strings.TrimPrefix(repoPath, absReposPath)
- // check if it's publicly readable
- if CanRead("public", relativeRepoPath) {
- fmt.Fprintf(fp, "%s = %s\n", relativeRepoPath, repoPath)
- return filepath.SkipDir
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/access/repositories.go Wed Apr 12 23:40:09 2023 -0500
@@ -0,0 +1,42 @@
+func refreshRepositories() error { + absReposPath, err := filepath.Abs(ReposPath()) + repositories = make(map[string]string) + // walk the reposPath, looking for .hg directories, when one is found, + // check if it is publicly readable, and if so, add it to the config file. + filepath.WalkDir(absReposPath, func(filename string, entry os.DirEntry, err error) error { + // check if we're looking at a directory + // check if it is a .hg directory + if !strings.HasSuffix(entry.Name(), ".hg") { + // figure out the repo path that we will be checking against the casbin + // stuff. That means it needs to be the exact path of the repo and not + // include the parent directory. + repoPath := path.Dir(filename) + relativeRepoPath := strings.TrimPrefix(repoPath, absReposPath) + repositories[strings.Trim(relativeRepoPath, "\\/")] = repoPath + return filepath.SkipDir