aboutsummaryrefslogtreecommitdiff
path: root/internal/repoutil
diff options
context:
space:
mode:
Diffstat (limited to 'internal/repoutil')
-rw-r--r--internal/repoutil/repoutil.go13
-rw-r--r--internal/repoutil/repoutil_test.go36
2 files changed, 49 insertions, 0 deletions
diff --git a/internal/repoutil/repoutil.go b/internal/repoutil/repoutil.go
index 658f896f..bb5afc08 100644
--- a/internal/repoutil/repoutil.go
+++ b/internal/repoutil/repoutil.go
@@ -7,6 +7,7 @@ package repoutil
import (
"fmt"
"path/filepath"
+ "strconv"
"strings"
"gogs.io/gogs/internal/conf"
@@ -60,3 +61,15 @@ func UserPath(user string) string {
func RepositoryPath(owner, repo string) string {
return filepath.Join(UserPath(owner), strings.ToLower(repo)+".git")
}
+
+// RepositoryLocalPath returns the absolute path of the repository local copy
+// with the given ID.
+func RepositoryLocalPath(repoID int64) string {
+ return filepath.Join(conf.Server.AppDataPath, "tmp", "local-repo", strconv.FormatInt(repoID, 10))
+}
+
+// RepositoryLocalWikiPath returns the absolute path of the repository local
+// wiki copy with the given ID.
+func RepositoryLocalWikiPath(repoID int64) string {
+ return filepath.Join(conf.Server.AppDataPath, "tmp", "local-wiki", strconv.FormatInt(repoID, 10))
+}
diff --git a/internal/repoutil/repoutil_test.go b/internal/repoutil/repoutil_test.go
index 232ecc52..cd0e7e44 100644
--- a/internal/repoutil/repoutil_test.go
+++ b/internal/repoutil/repoutil_test.go
@@ -125,3 +125,39 @@ func TestRepositoryPath(t *testing.T) {
want := "/home/git/gogs-repositories/alice/example.git"
assert.Equal(t, want, got)
}
+
+func TestRepositoryLocalPath(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("Skipping testing on Windows")
+ return
+ }
+
+ conf.SetMockServer(
+ t,
+ conf.ServerOpts{
+ AppDataPath: "data",
+ },
+ )
+
+ got := RepositoryLocalPath(1)
+ want := "data/tmp/local-repo/1"
+ assert.Equal(t, want, got)
+}
+
+func TestRepositoryLocalWikiPath(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("Skipping testing on Windows")
+ return
+ }
+
+ conf.SetMockServer(
+ t,
+ conf.ServerOpts{
+ AppDataPath: "data",
+ },
+ )
+
+ got := RepositoryLocalWikiPath(1)
+ want := "data/tmp/local-wiki/1"
+ assert.Equal(t, want, got)
+}