Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2020-01-24 02:08:19 +0300
committerPaul Okstad <pokstad@gitlab.com>2020-01-24 02:08:19 +0300
commit66d0227142a244858f83dce4127c7d1851779634 (patch)
tree84bcb53e84c6e662971e6a784c9a22b94df3c90f /internal
parentc283c088ff681c9008d0e921bfa3d8bc9dc46bf5 (diff)
Make parent directories before snapshot replication
Diffstat (limited to 'internal')
-rw-r--r--internal/praefect/replicator_test.go4
-rw-r--r--internal/service/repository/replicate.go4
-rw-r--r--internal/testhelper/testhelper.go17
3 files changed, 22 insertions, 3 deletions
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go
index 96d1eb8ad..c43ff5cdd 100644
--- a/internal/praefect/replicator_test.go
+++ b/internal/praefect/replicator_test.go
@@ -138,7 +138,9 @@ func TestProcessReplicationJob(t *testing.T) {
replMgr.processReplJob(ctx, jobs[0])
- replicatedPath := filepath.Join(backupDir, filepath.Base(testRepoPath))
+ relativeRepoPath, err := filepath.Rel(testhelper.GitlabTestStoragePath(), testRepoPath)
+ require.NoError(t, err)
+ replicatedPath := filepath.Join(backupDir, relativeRepoPath)
testhelper.MustRunCommand(t, nil, "git", "-C", replicatedPath, "cat-file", "-e", commitID)
testhelper.MustRunCommand(t, nil, "git", "-C", replicatedPath, "gc")
diff --git a/internal/service/repository/replicate.go b/internal/service/repository/replicate.go
index ff8bd422b..56f211809 100644
--- a/internal/service/repository/replicate.go
+++ b/internal/service/repository/replicate.go
@@ -141,6 +141,10 @@ func (s *server) createFromSnapshot(ctx context.Context, in *gitalypb.ReplicateR
return err
}
+ if err = os.MkdirAll(filepath.Dir(targetPath), 0755); err != nil {
+ return err
+ }
+
if err := os.Rename(tempPath, targetPath); err != nil {
return err
}
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index 7f1a24752..a052c5119 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -5,6 +5,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
+ "errors"
"fmt"
"io"
"io/ioutil"
@@ -385,13 +386,25 @@ func Context() (context.Context, func()) {
return context.WithCancel(context.Background())
}
+func hashedRepoPath(dirName string) (string, error) {
+ if len(dirName) < 4 {
+ return "", errors.New("dirname is too short")
+ }
+
+ return filepath.Join(dirName[0:2], dirName[2:4], dirName[4:]), nil
+}
+
// CreateRepo creates a temporary directory for a repo, without initializing it
func CreateRepo(t testing.TB, storagePath string) (repo *gitalypb.Repository, repoPath, relativePath string) {
- normalizedPrefix := strings.Replace(t.Name(), "/", "-", -1) //TempDir doesn't like a prefix containing slashes
+ random, err := text.RandomHex(20)
+ require.NoError(t, err)
- repoPath, err := ioutil.TempDir(storagePath, normalizedPrefix)
+ hashedPath, err := hashedRepoPath(random)
require.NoError(t, err)
+ repoPath = filepath.Join(storagePath, hashedPath)
+ require.NoError(t, os.MkdirAll(filepath.Dir(repoPath), 0755), "making repo parent dir")
+
relativePath, err = filepath.Rel(storagePath, repoPath)
require.NoError(t, err)
repo = &gitalypb.Repository{StorageName: "default", RelativePath: relativePath, GlRepository: "project-1"}