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:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-08-31 02:10:50 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-08-31 02:10:50 +0300
commit9990bdd440e360d49e5fb3ad56641bdf1e7e719d (patch)
tree87a14e298b8b506686976d06bd3defb549c93775
parente251e0b874aff5a6d898cdadb570e3632d05c310 (diff)
parentf696d3fef3a0104f42e4021a6e4a45ed4d2a63be (diff)
Merge branch 'custom-hooks-symlink' into 'master'
Support custom_hooks being a symlink See merge request gitlab-org/gitaly!871
-rw-r--r--changelogs/unreleased/custom-hooks-symlink.yml5
-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
4 files changed, 59 insertions, 7 deletions
diff --git a/changelogs/unreleased/custom-hooks-symlink.yml b/changelogs/unreleased/custom-hooks-symlink.yml
new file mode 100644
index 000000000..9a0ee2b58
--- /dev/null
+++ b/changelogs/unreleased/custom-hooks-symlink.yml
@@ -0,0 +1,5 @@
+---
+title: Support custom_hooks being a symlink
+merge_request: 871
+author:
+type: fixed
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()