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:
authorOswaldo Ferreira <oswaldo@gitlab.com>2018-12-19 21:44:47 +0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2018-12-20 00:08:32 +0300
commit22b78ecd07fd55d644e7d05c5e42bf33942048a6 (patch)
treec9002c8d9c1eddbde4dcdbce6e35a39354a3635e
parent06e11d22ef0b4abb20118dd0293631652954fddf (diff)
Support namespace overriding through Override flagosw-support-namespace-overriting
-rw-r--r--changelogs/unreleased/osw-support-namespace-overriting.yml5
-rw-r--r--internal/service/namespace/namespace.go19
-rw-r--r--internal/service/namespace/namespace_test.go68
-rw-r--r--vendor/gitlab.com/gitlab-org/gitaly-proto/go/gitalypb/namespace.pb.go49
-rw-r--r--vendor/vendor.json10
5 files changed, 125 insertions, 26 deletions
diff --git a/changelogs/unreleased/osw-support-namespace-overriting.yml b/changelogs/unreleased/osw-support-namespace-overriting.yml
new file mode 100644
index 000000000..2413fac0d
--- /dev/null
+++ b/changelogs/unreleased/osw-support-namespace-overriting.yml
@@ -0,0 +1,5 @@
+---
+title: Support namespace overriding through Override flag
+merge_request: 1011
+author:
+type: fixed
diff --git a/internal/service/namespace/namespace.go b/internal/service/namespace/namespace.go
index ef8abffe0..f12835e01 100644
--- a/internal/service/namespace/namespace.go
+++ b/internal/service/namespace/namespace.go
@@ -62,6 +62,25 @@ func (s *server) RenameNamespace(ctx context.Context, in *gitalypb.RenameNamespa
return nil, status.Errorf(codes.InvalidArgument, "from and to cannot be empty")
}
+ if in.Override {
+ // Once it'll force a destination deletion, it should make sure the source exists
+ // in order to avoid getting into a state where the destination gets deleted
+ // and the source doesn't exists either.
+ fromExistsCheck := &gitalypb.NamespaceExistsRequest{StorageName: in.StorageName, Name: in.GetFrom()}
+ if fromExistsCheck, err := s.NamespaceExists(ctx, fromExistsCheck); err != nil {
+ return nil, err
+ } else if !fromExistsCheck.Exists {
+ return nil, status.Errorf(codes.InvalidArgument, "from directory %s not found", in.GetFrom())
+ }
+
+ // The os.Rename isn't able to handle folder renaming to a destination that already
+ // exists. Therefore, when Override flag is sent, we remove the destination entirely.
+ toRemoval := &gitalypb.RemoveNamespaceRequest{StorageName: in.StorageName, Name: in.GetTo()}
+ if _, err := s.RemoveNamespace(ctx, toRemoval); err != nil {
+ return nil, err
+ }
+ }
+
// No need to check if the from path exists, if it doesn't, we'd later get an
// os.LinkError
toExistsCheck := &gitalypb.NamespaceExistsRequest{StorageName: in.StorageName, Name: in.GetTo()}
diff --git a/internal/service/namespace/namespace_test.go b/internal/service/namespace/namespace_test.go
index f5ac3471f..50b84eb62 100644
--- a/internal/service/namespace/namespace_test.go
+++ b/internal/service/namespace/namespace_test.go
@@ -274,6 +274,36 @@ func TestRenameNamespace(t *testing.T) {
},
errorCode: codes.InvalidArgument,
},
+ {
+ desc: "override flag and destination namespace exists",
+ request: &gitalypb.RenameNamespaceRequest{
+ From: "existing-2",
+ To: "existing-3",
+ StorageName: "default",
+ Override: true,
+ },
+ errorCode: codes.OK,
+ },
+ {
+ desc: "override flag and non-existing destination namespace",
+ request: &gitalypb.RenameNamespaceRequest{
+ From: "existing-4",
+ To: "another-path",
+ StorageName: "default",
+ Override: true,
+ },
+ errorCode: codes.OK,
+ },
+ {
+ desc: "override flag and non-existing source namespace",
+ request: &gitalypb.RenameNamespaceRequest{
+ From: "non-existing",
+ To: "existing-4",
+ StorageName: "default",
+ Override: true,
+ },
+ errorCode: codes.InvalidArgument,
+ },
}
_, err := client.AddNamespace(ctx, &gitalypb.AddNamespaceRequest{
@@ -282,6 +312,30 @@ func TestRenameNamespace(t *testing.T) {
})
require.NoError(t, err)
+ _, err = client.AddNamespace(ctx, &gitalypb.AddNamespaceRequest{
+ StorageName: "default",
+ Name: "existing-2",
+ })
+ require.NoError(t, err)
+
+ _, err = client.AddNamespace(ctx, &gitalypb.AddNamespaceRequest{
+ StorageName: "default",
+ Name: "existing-3",
+ })
+ require.NoError(t, err)
+
+ _, err = client.AddNamespace(ctx, &gitalypb.AddNamespaceRequest{
+ StorageName: "default",
+ Name: "existing-4",
+ })
+ require.NoError(t, err)
+
+ _, err = client.AddNamespace(ctx, &gitalypb.AddNamespaceRequest{
+ StorageName: "default",
+ Name: "existing-5",
+ })
+ require.NoError(t, err)
+
for _, tc := range queries {
t.Run(tc.desc, func(t *testing.T) {
_, err := client.RenameNamespace(ctx, tc.request)
@@ -289,9 +343,21 @@ func TestRenameNamespace(t *testing.T) {
require.Equal(t, tc.errorCode, helper.GrpcCode(err))
if tc.errorCode == codes.OK {
+ srcExistsReq := &gitalypb.NamespaceExistsRequest{StorageName: tc.request.StorageName, Name: tc.request.From}
+ srcExists, err := client.NamespaceExists(ctx, srcExistsReq)
+ require.NoError(t, err)
+
+ require.False(t, srcExists.Exists)
+
+ dstExistsReq := &gitalypb.NamespaceExistsRequest{StorageName: tc.request.StorageName, Name: tc.request.To}
+ dstExists, err := client.NamespaceExists(ctx, dstExistsReq)
+ require.NoError(t, err)
+
+ require.True(t, dstExists.Exists)
+
client.RemoveNamespace(ctx, &gitalypb.RemoveNamespaceRequest{
StorageName: "default",
- Name: "new-path",
+ Name: tc.request.To,
})
}
})
diff --git a/vendor/gitlab.com/gitlab-org/gitaly-proto/go/gitalypb/namespace.pb.go b/vendor/gitlab.com/gitlab-org/gitaly-proto/go/gitalypb/namespace.pb.go
index 3976a4ce9..c0a701752 100644
--- a/vendor/gitlab.com/gitlab-org/gitaly-proto/go/gitalypb/namespace.pb.go
+++ b/vendor/gitlab.com/gitlab-org/gitaly-proto/go/gitalypb/namespace.pb.go
@@ -69,6 +69,7 @@ type RenameNamespaceRequest struct {
StorageName string `protobuf:"bytes,1,opt,name=storage_name,json=storageName" json:"storage_name,omitempty"`
From string `protobuf:"bytes,2,opt,name=from" json:"from,omitempty"`
To string `protobuf:"bytes,3,opt,name=to" json:"to,omitempty"`
+ Override bool `protobuf:"varint,4,opt,name=override" json:"override,omitempty"`
}
func (m *RenameNamespaceRequest) Reset() { *m = RenameNamespaceRequest{} }
@@ -97,6 +98,13 @@ func (m *RenameNamespaceRequest) GetTo() string {
return ""
}
+func (m *RenameNamespaceRequest) GetOverride() bool {
+ if m != nil {
+ return m.Override
+ }
+ return false
+}
+
type NamespaceExistsRequest struct {
StorageName string `protobuf:"bytes,1,opt,name=storage_name,json=storageName" json:"storage_name,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
@@ -346,24 +354,25 @@ var _NamespaceService_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("namespace.proto", fileDescriptor5) }
var fileDescriptor5 = []byte{
- // 291 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcf, 0x4b, 0xcc, 0x4d,
- 0x2d, 0x2e, 0x48, 0x4c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4b, 0xcf, 0x2c,
- 0x49, 0xcc, 0xa9, 0x54, 0xf2, 0xe1, 0x12, 0x76, 0x4c, 0x49, 0xf1, 0x83, 0xc9, 0x06, 0xa5, 0x16,
- 0x96, 0xa6, 0x16, 0x97, 0x08, 0x29, 0x72, 0xf1, 0x14, 0x97, 0xe4, 0x17, 0x25, 0xa6, 0xa7, 0xc6,
- 0x83, 0x74, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x71, 0x43, 0xc5, 0x40, 0xca, 0x85, 0x84,
- 0xb8, 0x58, 0xc0, 0x52, 0x4c, 0x60, 0x29, 0x30, 0x5b, 0xc9, 0x9f, 0x4b, 0x2c, 0x28, 0x35, 0x37,
- 0xbf, 0x2c, 0x95, 0x5a, 0x06, 0xc6, 0x83, 0x0c, 0x04, 0xb1, 0xc8, 0x34, 0x30, 0xad, 0x28, 0x3f,
- 0x17, 0x66, 0x20, 0x88, 0x2d, 0xc4, 0xc7, 0xc5, 0x54, 0x92, 0x2f, 0xc1, 0x0c, 0x16, 0x61, 0x2a,
- 0xc9, 0x07, 0xb9, 0x18, 0x6e, 0xb4, 0x6b, 0x45, 0x66, 0x71, 0x49, 0x31, 0x85, 0x2e, 0x36, 0xe4,
- 0x12, 0xc7, 0x30, 0xb0, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x48, 0x8c, 0x8b, 0x2d, 0x15, 0x2c,
- 0x02, 0x36, 0x8b, 0x23, 0x08, 0xca, 0x53, 0x12, 0xe3, 0x12, 0x41, 0x8d, 0x03, 0x88, 0x7a, 0x25,
- 0x49, 0x2e, 0x71, 0x8c, 0xd0, 0x44, 0x96, 0x42, 0x0b, 0x17, 0x88, 0x94, 0xd1, 0x43, 0x26, 0x2e,
- 0x01, 0xb8, 0x68, 0x70, 0x6a, 0x51, 0x59, 0x66, 0x72, 0xaa, 0x90, 0x37, 0x17, 0x0f, 0xb2, 0x15,
- 0x42, 0xd2, 0x7a, 0x90, 0xf8, 0xd7, 0xc3, 0x12, 0xf9, 0x52, 0x32, 0xd8, 0x25, 0xa1, 0x56, 0x33,
- 0x08, 0x85, 0x70, 0xf1, 0xa3, 0xb9, 0x4b, 0x48, 0x0e, 0xa6, 0x05, 0x7b, 0xf4, 0x4b, 0xc9, 0xe3,
- 0x94, 0x47, 0x35, 0x15, 0xc5, 0x4b, 0xc8, 0xa6, 0x62, 0x4b, 0x03, 0xc8, 0xa6, 0x62, 0x0d, 0x0b,
- 0x88, 0xa9, 0x68, 0xd1, 0x81, 0x30, 0x15, 0x7b, 0xc4, 0x23, 0x4c, 0xc5, 0x11, 0x8f, 0x4a, 0x0c,
- 0x49, 0x6c, 0xe0, 0x4c, 0x64, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x36, 0x4b, 0x73, 0x57,
- 0x03, 0x00, 0x00,
+ // 308 bytes of a gzipped FileDescriptorProto
+ 0x1f,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8a, 0x3f, 0x76, 0x73, 0x0e, 0x93, 0x35, 0xa0, 0xc8, 0xd8, 0x52,
+ 0x10, 0x3a, 0x30, 0x24, 0x9d, 0xd1, 0x2c, 0x3b, 0x2c, 0x4f, 0xbe, 0x03, 0x07, 0xed, 0xfd, 0x14,
+ 0xf7, 0xfd, 0x43, 0x98, 0xac, 0x4d, 0xba, 0x29, 0x75, 0x66, 0x56, 0x48, 0x17, 0xdf, 0x16, 0xec,
+ 0xd5, 0xd9, 0x07, 0xe2, 0x79, 0x32, 0x27, 0xbc, 0x81, 0x51, 0xb3, 0x04, 0x1e, 0x05, 0x85, 0x37,
+ 0x02, 0x83, 0x31, 0xbc, 0x63, 0xb3, 0x58, 0x96, 0xee, 0xe1, 0x23, 0x8c, 0x3b, 0xdf, 0x85, 0x27,
+ 0xd5, 0x13, 0xb3, 0x35, 0xbc, 0xd3, 0x8d, 0x7a, 0x9b, 0xda, 0x6a, 0xa9, 0x49, 0x35, 0xf9, 0xa3,
+ 0x49, 0x35, 0xce, 0xa2, 0xa0, 0x76, 0xd6, 0xb1, 0xa2, 0x9a, 0x17, 0xbf, 0xa2, 0x6e, 0xd8, 0xa3,
+ 0xdf, 0x7b, 0x1e, 0xea, 0x1f, 0xec, 0xf2, 0x27, 0x00, 0x00, 0xff, 0xff, 0x33, 0xf7, 0xac, 0x87,
+ 0x73, 0x03, 0x00, 0x00,
}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index 7f09cf4f2..4aa21f289 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -315,12 +315,12 @@
"versionExact": "v1.2.2"
},
{
- "checksumSHA1": "VpLdojyLYx9d/bwnqFkEy12sNd8=",
+ "checksumSHA1": "wrF4y4iwaGN1YvpalGvreOwXgrM=",
"path": "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb",
- "revision": "20e398e887e239ba4ddaa44cf075e99841e43f8a",
- "revisionTime": "2018-12-17T08:03:04Z",
- "version": "v1.5.0",
- "versionExact": "v1.5.0"
+ "revision": "86e1bbb7790e872878e9b9813675070d1b1e6833",
+ "revisionTime": "2018-12-19T13:05:19Z",
+ "version": "osw-add-overrite-flag-to-rename-namespace",
+ "versionExact": "osw-add-overrite-flag-to-rename-namespace"
},
{
"checksumSHA1": "S9x46Eq79I1EkoXI8woeIU6w/wY=",