diff --git a/khatru/grasp/helpers.go b/khatru/grasp/helpers.go index 87efa19..5aa69f7 100644 --- a/khatru/grasp/helpers.go +++ b/khatru/grasp/helpers.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "path/filepath" "slices" "strings" @@ -142,6 +143,10 @@ func (gs *GraspServer) validatePush( return nil } +func (gs *GraspServer) getRepositoryPath(pubkey nostr.PubKey, repoName string) string { + return filepath.Join(gs.RepositoryDir, pubkey.Hex(), repoName) +} + // repoExists checks if a repository has an announcement event (kind 30617) func (gs *GraspServer) repoExists(pubkey nostr.PubKey, repoName string) bool { for range gs.Relay.QueryStored(context.Background(), nostr.Filter{ diff --git a/khatru/grasp/info.go b/khatru/grasp/info.go index 9c8bb00..829163c 100644 --- a/khatru/grasp/info.go +++ b/khatru/grasp/info.go @@ -7,7 +7,6 @@ import ( "net/http" "os" "os/exec" - "path/filepath" "strings" "syscall" @@ -28,7 +27,7 @@ func (gs *GraspServer) handleInfoRefs( return } - repoPath := filepath.Join(gs.RepositoryDir, repoName) + repoPath := gs.getRepositoryPath(pubkey, repoName) serviceName := r.URL.Query().Get("service") w.Header().Set("Connection", "Keep-Alive") diff --git a/khatru/grasp/read.go b/khatru/grasp/read.go index 2658fac..dd51ed9 100644 --- a/khatru/grasp/read.go +++ b/khatru/grasp/read.go @@ -8,7 +8,6 @@ import ( "net/http" "os" "os/exec" - "path/filepath" "syscall" "fiatjaf.com/nostr" @@ -20,7 +19,7 @@ func (gs *GraspServer) handleGitUploadPack( pubkey nostr.PubKey, repoName string, ) { - repoPath := filepath.Join(gs.RepositoryDir, repoName) + repoPath := gs.getRepositoryPath(pubkey, repoName) // for upload-pack (pull), check if repository exists if !gs.repoExists(pubkey, repoName) { diff --git a/khatru/grasp/write.go b/khatru/grasp/write.go index c1a0297..a261244 100644 --- a/khatru/grasp/write.go +++ b/khatru/grasp/write.go @@ -8,7 +8,6 @@ import ( "net/http" "os" "os/exec" - "path/filepath" "strings" "sync" "syscall" @@ -45,7 +44,7 @@ func (gs *GraspServer) handleGitReceivePack( } } - repoPath := filepath.Join(gs.RepositoryDir, repoName) + repoPath := gs.getRepositoryPath(pubkey, repoName) // initialize git repo if it doesn't exist if _, err := os.Stat(repoPath); os.IsNotExist(err) {