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:
authorJacob Vosmaer <jacob@gitlab.com>2018-08-27 16:49:09 +0300
committerJacob Vosmaer <jacob@gitlab.com>2018-08-27 16:49:09 +0300
commitcd0774e10c8f83c90824d2d4e6ae91b57afab271 (patch)
tree8383e0311aac5d4ddc99b068e664fa82e43158f8
parentac71ee6271e2b545a063a3598531d53cb0928ef5 (diff)
Support custom_hooks being a symlink
-rw-r--r--internal/service/repository/backup_custom_hooks.go20
-rw-r--r--internal/service/repository/backup_custom_hooks_test.go39
-rw-r--r--internal/service/repository/restore_custom_hooks.go2
3 files changed, 54 insertions, 7 deletions
diff --git a/internal/service/repository/backup_custom_hooks.go b/internal/service/repository/backup_custom_hooks.go
index ba5ec526e..12fabc7f0 100644
--- a/internal/service/repository/backup_custom_hooks.go
+++ b/internal/service/repository/backup_custom_hooks.go
@@ -2,16 +2,19 @@ package repository
import (
"os"
+ "os/exec"
"path"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
- "gitlab.com/gitlab-org/gitaly/internal/archive"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/streamio"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
+const customHooksDir = "custom_hooks"
+
func (s *server) BackupCustomHooks(in *pb.BackupCustomHooksRequest, stream pb.RepositoryService_BackupCustomHooksServer) error {
repoPath, err := helper.GetPath(in.Repository)
if err != nil {
@@ -22,14 +25,19 @@ func (s *server) BackupCustomHooks(in *pb.BackupCustomHooksRequest, stream pb.Re
return stream.Send(&pb.BackupCustomHooksResponse{Data: p})
})
- if _, err := os.Lstat(path.Join(repoPath, "custom_hooks")); os.IsNotExist(err) {
+ if _, err := os.Lstat(path.Join(repoPath, customHooksDir)); os.IsNotExist(err) {
return nil
}
- builder := archive.NewTarBuilder(repoPath, writer)
- builder.RecursiveDirIfExist("custom_hooks")
- if err = builder.Close(); err != nil {
- return status.Errorf(codes.Internal, "BackupCustomHooks: adding custom_hooks failed: %v", err)
+ ctx := stream.Context()
+ tar := exec.Command("tar", "-c", "-f", "-", "-C", repoPath, customHooksDir)
+ cmd, err := command.New(ctx, tar, nil, writer, nil)
+ if err != nil {
+ return status.Errorf(codes.Internal, "%v", err)
+ }
+
+ if err := cmd.Wait(); err != nil {
+ return status.Errorf(codes.Internal, "%v", err)
}
return nil
diff --git a/internal/service/repository/backup_custom_hooks_test.go b/internal/service/repository/backup_custom_hooks_test.go
index 27ed1db1b..94c7a96a9 100644
--- a/internal/service/repository/backup_custom_hooks_test.go
+++ b/internal/service/repository/backup_custom_hooks_test.go
@@ -68,6 +68,45 @@ func TestSuccessfullBackupCustomHooksRequest(t *testing.T) {
require.Equal(t, fileLength, len(expectedTarResponse))
}
+func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) {
+ server, serverSocketPath := runRepoServer(t)
+ defer server.Stop()
+
+ client, conn := newRepositoryClient(t, serverSocketPath)
+ defer conn.Close()
+
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
+ defer cleanupFn()
+
+ repoPath, err := helper.GetPath(testRepo)
+ require.NoError(t, err)
+
+ linkTarget := "/var/empty"
+ require.NoError(t, os.Symlink(linkTarget, path.Join(repoPath, "custom_hooks")), "Could not create custom_hooks symlink")
+
+ backupRequest := &pb.BackupCustomHooksRequest{Repository: testRepo}
+ backupStream, err := client.BackupCustomHooks(ctx, backupRequest)
+ require.NoError(t, err)
+
+ reader := tar.NewReader(streamio.NewReader(func() ([]byte, error) {
+ response, err := backupStream.Recv()
+ return response.GetData(), err
+ }))
+
+ file, err := reader.Next()
+ require.NoError(t, err)
+
+ require.Equal(t, "custom_hooks", file.Name, "tar entry name")
+ require.Equal(t, byte(tar.TypeSymlink), file.Typeflag, "tar entry type")
+ require.Equal(t, linkTarget, file.Linkname, "link target")
+
+ _, err = reader.Next()
+ require.Equal(t, io.EOF, err, "custom_hooks should have been the only entry")
+}
+
func TestSuccessfullBackupCustomHooksRequestWithNoHooks(t *testing.T) {
server, serverSocketPath := runRepoServer(t)
defer server.Stop()
diff --git a/internal/service/repository/restore_custom_hooks.go b/internal/service/repository/restore_custom_hooks.go
index f920ce763..988f7fbd2 100644
--- a/internal/service/repository/restore_custom_hooks.go
+++ b/internal/service/repository/restore_custom_hooks.go
@@ -43,7 +43,7 @@ func (s *server) RestoreCustomHooks(stream pb.RepositoryService_RestoreCustomHoo
"-",
"-C",
repoPath,
- "custom_hooks",
+ customHooksDir,
}
ctx := stream.Context()