grim/hgkeeper

5f030be0a76c
Parents 5a19892df841
Children 9f9a854ed3b3
Pass absolute path since we already have it

Reviewed at https://reviews.imfreedom.org/r/2424/
--- a/access/repositories.go Thu Apr 13 00:05:31 2023 -0500
+++ b/access/repositories.go Thu Apr 13 00:10:58 2023 -0500
@@ -14,7 +14,7 @@
realRepoName := strings.Trim(strings.TrimPrefix(absPath, reposPath), "\\/")
if strings.HasPrefix(absPath, reposPath) && len(realRepoName) > 0 && !strings.Contains(repoName, "/../") {
- return reposPath, realRepoName
+ return filepath.Join(reposPath, realRepoName), realRepoName
}
zap.S().Infof("repository invalid: %q", repoName)
--- a/once/command.go Thu Apr 13 00:05:31 2023 -0500
+++ b/once/command.go Thu Apr 13 00:10:58 2023 -0500
@@ -3,7 +3,6 @@
import (
"fmt"
"os"
- "path/filepath"
"keep.imfreedom.org/grim/hgkeeper/access"
"keep.imfreedom.org/grim/hgkeeper/globals"
@@ -14,30 +13,30 @@
User string `kong:"arg,help='The username who is trying to access the repositories'"`
}
-func (c *Command) serve(reposPath, repoPath string) error {
- if !access.CanRead(c.User, "/"+repoPath) {
- return fmt.Errorf("repository %q not found", repoPath)
+func (c *Command) serve(repoPath, repoName string) error {
+ if !access.CanRead(c.User, "/"+repoName) {
+ return fmt.Errorf("repository %q not found", repoName)
}
- writeable := access.CanWrite(c.User, "/"+repoPath)
+ writeable := access.CanWrite(c.User, "/"+repoName)
- hgcmd := hg.Serve(filepath.Join(reposPath, repoPath), writeable)
+ hgcmd := hg.Serve(repoPath, writeable)
- return hgcmd.ExecPiped(repoPath, c.User, os.Stdin, os.Stdout, os.Stderr)
+ return hgcmd.ExecPiped(repoName, c.User, os.Stdin, os.Stdout, os.Stderr)
}
-func (c *Command) init(reposPath, repoPath string) error {
- if !access.CanInit(c.User, "/"+repoPath) {
+func (c *Command) init(repoPath, repoName string) error {
+ if !access.CanInit(c.User, "/"+repoName) {
return fmt.Errorf("access denied")
}
- if access.IsInExistingRepo(repoPath) {
+ if access.IsInExistingRepo(repoName) {
return fmt.Errorf("repository in repository is forbidden")
}
- hgcmd := hg.Init(filepath.Join(reposPath, repoPath))
+ hgcmd := hg.Init(repoPath)
- return hgcmd.ExecPiped(repoPath, c.User, os.Stdin, os.Stdout, os.Stderr)
+ return hgcmd.ExecPiped(repoName, c.User, os.Stdin, os.Stdout, os.Stderr)
}
func (c *Command) Run(g *globals.Globals) error {
--- a/ssh/commands/init.go Thu Apr 13 00:05:31 2023 -0500
+++ b/ssh/commands/init.go Thu Apr 13 00:10:58 2023 -0500
@@ -2,7 +2,6 @@
import (
"fmt"
- "path/filepath"
"github.com/gliderlabs/ssh"
"go.uber.org/zap"
@@ -16,9 +15,9 @@
repoName string
}
-func NewInit(reposPath, repoName string) *Init {
+func NewInit(repoPath, repoName string) *Init {
return &Init{
- repoPath: filepath.Join(reposPath, repoName),
+ repoPath: repoPath,
repoName: repoName,
}
}
--- a/ssh/commands/rm.go Thu Apr 13 00:05:31 2023 -0500
+++ b/ssh/commands/rm.go Thu Apr 13 00:10:58 2023 -0500
@@ -3,7 +3,6 @@
import (
"fmt"
"os"
- "path/filepath"
"github.com/gliderlabs/ssh"
"go.uber.org/zap"
@@ -16,9 +15,9 @@
repoName string
}
-func NewRemove(reposPath, repoName string) Command {
+func NewRemove(repoPath, repoName string) Command {
return &Remove{
- repoPath: filepath.Join(reposPath, repoName),
+ repoPath: repoPath,
repoName: repoName,
}
}
--- a/ssh/commands/serve.go Thu Apr 13 00:05:31 2023 -0500
+++ b/ssh/commands/serve.go Thu Apr 13 00:10:58 2023 -0500
@@ -2,7 +2,6 @@
import (
"fmt"
- "path/filepath"
"github.com/gliderlabs/ssh"
"go.uber.org/zap"
@@ -16,9 +15,9 @@
repoName string
}
-func NewServe(reposPath, repoName string) *Serve {
+func NewServe(repoPath, repoName string) *Serve {
return &Serve{
- repoPath: filepath.Join(reposPath, repoName),
+ repoPath: repoPath,
repoName: repoName,
}
}