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:
authorPaul Okstad <pokstad@gitlab.com>2019-09-25 22:05:33 +0300
committerPaul Okstad <pokstad@gitlab.com>2019-09-25 22:05:33 +0300
commiteaf03c02d1bec230896239f9ab0ac96449fcef1b (patch)
treef301bc77546d3a14f154499a375c20d6aa0a10bd
parentd6edac6a132bd68aca86baab7ce420c31c3e9b1c (diff)
parent59a78fe66d233b518f0578a0e94567a471c88c84 (diff)
Merge branch 'jc-move-cache-dir-to-plus-gitaly' into 'master'
Move cache state files to +gitaly directory See merge request gitlab-org/gitaly!1515
-rw-r--r--changelogs/unreleased/jc-move-cache-dir-to-plus-gitaly.yml5
-rw-r--r--internal/cache/keyer.go46
-rw-r--r--internal/tempdir/tempdir.go7
3 files changed, 45 insertions, 13 deletions
diff --git a/changelogs/unreleased/jc-move-cache-dir-to-plus-gitaly.yml b/changelogs/unreleased/jc-move-cache-dir-to-plus-gitaly.yml
new file mode 100644
index 000000000..deec9375c
--- /dev/null
+++ b/changelogs/unreleased/jc-move-cache-dir-to-plus-gitaly.yml
@@ -0,0 +1,5 @@
+---
+title: Move cache state files to +gitaly directory
+merge_request: 1515
+author:
+type: other
diff --git a/internal/cache/keyer.go b/internal/cache/keyer.go
index cdebd4fa9..b7cc5e529 100644
--- a/internal/cache/keyer.go
+++ b/internal/cache/keyer.go
@@ -76,12 +76,12 @@ func (l lease) EndLease(ctx context.Context) error {
}
func updateLatest(repo *gitalypb.Repository) (string, error) {
- repoPath, err := helper.GetPath(repo)
+ repoStatePath, err := getRepoStatePath(repo)
if err != nil {
return "", err
}
- lPath := latestPath(repoPath)
+ lPath := latestPath(repoStatePath)
if err := os.MkdirAll(filepath.Dir(lPath), 0755); err != nil {
return "", err
}
@@ -141,12 +141,12 @@ func (LeaseKeyer) KeyPath(ctx context.Context, repo *gitalypb.Repository, req pr
return "", err
}
- repoPath, err := helper.GetPath(repo)
+ repoStatePath, err := getRepoStatePath(repo)
if err != nil {
return "", err
}
- pDir := pendingDir(repoPath)
+ pDir := pendingDir(repoStatePath)
anyValidPending := false
for _, p := range pending {
@@ -190,12 +190,12 @@ func radixPath(root, key string) (string, error) {
}
func newPendingLease(repo *gitalypb.Repository) (string, error) {
- repoPath, err := helper.GetPath(repo)
+ repoStatePath, err := getRepoStatePath(repo)
if err != nil {
return "", err
}
- pDir := pendingDir(repoPath)
+ pDir := pendingDir(repoStatePath)
if err := os.MkdirAll(pDir, 0755); err != nil {
return "", err
}
@@ -222,13 +222,33 @@ func cacheDir(repo *gitalypb.Repository) (string, error) {
return tempdir.CacheDir(storage), nil
}
+func getRepoStatePath(repo *gitalypb.Repository) (string, error) {
+ storage, ok := config.Config.Storage(repo.StorageName)
+ if !ok {
+ return "", fmt.Errorf("getRepoStatePath: storage not found for %v", repo)
+ }
+
+ stateDir := tempdir.StateDir(storage)
+
+ relativePath := repo.GetRelativePath()
+ if len(relativePath) == 0 {
+ return "", fmt.Errorf("getRepoStatePath: relative path missing from %+v", repo)
+ }
+
+ if helper.ContainsPathTraversal(relativePath) {
+ return "", fmt.Errorf("getRepoStatePath: relative path can't contain directory traversal")
+ }
+
+ return filepath.Join(stateDir, relativePath), nil
+}
+
func currentLeases(repo *gitalypb.Repository) ([]os.FileInfo, error) {
- repoPath, err := helper.GetPath(repo)
+ repoStatePath, err := getRepoStatePath(repo)
if err != nil {
return nil, err
}
- pendings, err := ioutil.ReadDir(pendingDir(repoPath))
+ pendings, err := ioutil.ReadDir(pendingDir(repoStatePath))
switch {
case os.IsNotExist(err):
// pending files subdir don't exist yet, that's okay
@@ -243,12 +263,12 @@ func currentLeases(repo *gitalypb.Repository) ([]os.FileInfo, error) {
}
func currentGenID(repo *gitalypb.Repository) (string, error) {
- repoPath, err := helper.GetPath(repo)
+ repoStatePath, err := getRepoStatePath(repo)
if err != nil {
return "", err
}
- latestBytes, err := ioutil.ReadFile(latestPath(repoPath))
+ latestBytes, err := ioutil.ReadFile(latestPath(repoStatePath))
switch {
case os.IsNotExist(err):
// latest file doesn't exist, so create one
@@ -260,9 +280,9 @@ func currentGenID(repo *gitalypb.Repository) (string, error) {
}
}
-func stateDir(repoDir string) string { return filepath.Join(repoDir, "state") }
-func pendingDir(repoDir string) string { return filepath.Join(stateDir(repoDir), "pending") }
-func latestPath(repoDir string) string { return filepath.Join(stateDir(repoDir), "latest") }
+//func stateDir(repoDir string) string { return filepath.Join(repoDir, "state") }
+func pendingDir(repoStateDir string) string { return filepath.Join(repoStateDir, "pending") }
+func latestPath(repoStateDir string) string { return filepath.Join(repoStateDir, "latest") }
// compositeKeyHashHex returns a hex encoded string that is a SHA256 hash sum of
// the composite key made up of the following properties: Gitaly version, gRPC
diff --git a/internal/tempdir/tempdir.go b/internal/tempdir/tempdir.go
index 8c5e4cdce..55e3be5e5 100644
--- a/internal/tempdir/tempdir.go
+++ b/internal/tempdir/tempdir.go
@@ -30,6 +30,10 @@ const (
// storage location.
cachePrefix = GitalyDataPrefix + "/cache"
+ // statePrefix is the directory where all state data is stored on a
+ // storage location.
+ statePrefix = GitalyDataPrefix + "/state"
+
// MaxAge is used by ForDeleteAllRepositories. It is also a fallback
// for the context-scoped temporary directories, to ensure they get
// cleaned up if the cleanup at the end of the context failed to run.
@@ -39,6 +43,9 @@ const (
// CacheDir returns the path to the cache dir for a storage location
func CacheDir(storage config.Storage) string { return filepath.Join(storage.Path, cachePrefix) }
+// StateDir returns the path to the state dir for a storage location
+func StateDir(storage config.Storage) string { return filepath.Join(storage.Path, statePrefix) }
+
// TempDir returns the path to the temp dir for a storage location
func TempDir(storage config.Storage) string { return filepath.Join(storage.Path, tmpRootPrefix) }