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

cleanrepos.go « internalgitaly « service « gitaly « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fac9a6f839f01b645bd37a4c71c8fe8559a8e10f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package internalgitaly

import (
	"context"
	"os"
	"path/filepath"
	"time"

	"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)

func (s *server) CleanRepos(ctx context.Context, req *gitalypb.CleanReposRequest) (*gitalypb.CleanReposResponse, error) {
	sPath, err := s.storagePath(req.GetStorageName())
	if err != nil {
		return nil, err
	}

	directory := filepath.Join(
		sPath,
		"lost+found",
		time.Now().Format("2006-01-02"),
	)

	if err := os.MkdirAll(directory, 0o750); err != nil {
		return nil, err
	}

	for _, relPath := range req.GetRelativePaths() {
		if err := os.Rename(
			filepath.Join(sPath, relPath),
			filepath.Join(directory, relPath),
		); err != nil {
			return nil, err
		}
	}

	return &gitalypb.CleanReposResponse{}, nil
}