Skip to content

Commit 3c2f7d9

Browse files
authored
Simplify delete file|dir to just delete path (#2181)
1 parent 1e3d3f9 commit 3c2f7d9

28 files changed

Lines changed: 980 additions & 1231 deletions

packages/api/internal/handlers/volume_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func isValidVolumeName(name string) bool {
174174

175175
func (a *APIStore) createVolume(ctx context.Context, clusterID uuid.UUID, volume queries.Volume) error {
176176
return a.executeOnOrchestratorByClusterID(ctx, clusterID, func(ctx context.Context, client *clusters.GRPCClient) error {
177-
_, err := client.Volumes.Create(ctx, &orchestrator.VolumeCreateRequest{
177+
_, err := client.Volumes.CreateVolume(ctx, &orchestrator.CreateVolumeRequest{
178178
Volume: toVolumeKey(volume),
179179
})
180180

packages/api/internal/handlers/volume_delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (a *APIStore) DeleteVolumesVolumeID(c *gin.Context, volumeID api.VolumeID)
4848

4949
func (a *APIStore) deleteVolume(ctx context.Context, clusterID uuid.UUID, volume queries.Volume) error {
5050
return a.executeOnOrchestratorByClusterID(ctx, clusterID, func(ctx context.Context, client *clusters.GRPCClient) error {
51-
_, err := client.Volumes.Delete(ctx, &orchestrator.VolumeDeleteRequest{
51+
_, err := client.Volumes.DeleteVolume(ctx, &orchestrator.DeleteVolumeRequest{
5252
Volume: toVolumeKey(volume),
5353
})
5454

packages/orchestrator/pkg/volumes/dir_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/e2b-dev/infra/packages/shared/pkg/utils"
1717
)
1818

19-
func (s *Service) CreateDir(ctx context.Context, request *orchestrator.VolumeDirCreateRequest) (r *orchestrator.VolumeDirCreateResponse, err error) {
19+
func (s *Service) CreateDir(ctx context.Context, request *orchestrator.CreateDirRequest) (r *orchestrator.CreateDirResponse, err error) {
2020
ctx, span := tracer.Start(ctx, "create directory in volume")
2121
defer func() {
2222
setSpanStatus(span, err)
@@ -82,7 +82,7 @@ func (s *Service) CreateDir(ctx context.Context, request *orchestrator.VolumeDir
8282

8383
entry := toEntry(path, stat)
8484

85-
return &orchestrator.VolumeDirCreateResponse{Entry: entry}, nil
85+
return &orchestrator.CreateDirResponse{Entry: entry}, nil
8686
}
8787

8888
func processError(ctx context.Context, s string, err error) error {

packages/orchestrator/pkg/volumes/dir_create_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestDirCreate(t *testing.T) {
2222
t.Parallel()
2323

2424
dirname := "test-dir"
25-
_, err := s.CreateDir(t.Context(), &orchestrator.VolumeDirCreateRequest{
25+
_, err := s.CreateDir(t.Context(), &orchestrator.CreateDirRequest{
2626
Volume: volumeInfo,
2727
Path: dirname,
2828
})
@@ -37,7 +37,7 @@ func TestDirCreate(t *testing.T) {
3737
t.Parallel()
3838

3939
dirname := "parent/child"
40-
_, err := s.CreateDir(t.Context(), &orchestrator.VolumeDirCreateRequest{
40+
_, err := s.CreateDir(t.Context(), &orchestrator.CreateDirRequest{
4141
Volume: volumeInfo,
4242
Path: dirname,
4343
CreateParents: true,
@@ -53,7 +53,7 @@ func TestDirCreate(t *testing.T) {
5353
t.Parallel()
5454

5555
dirname := "another-parent/child"
56-
_, err := s.CreateDir(t.Context(), &orchestrator.VolumeDirCreateRequest{
56+
_, err := s.CreateDir(t.Context(), &orchestrator.CreateDirRequest{
5757
Volume: volumeInfo,
5858
Path: dirname,
5959
CreateParents: false,
@@ -69,7 +69,7 @@ func TestDirCreate(t *testing.T) {
6969
uid := uint32(1000)
7070
gid := uint32(1000)
7171

72-
_, err := s.CreateDir(t.Context(), &orchestrator.VolumeDirCreateRequest{
72+
_, err := s.CreateDir(t.Context(), &orchestrator.CreateDirRequest{
7373
Volume: volumeInfo,
7474
Path: dirname,
7575
Mode: utils.ToPtr(mode),
@@ -90,7 +90,7 @@ func TestDirCreate(t *testing.T) {
9090
err := os.Mkdir(filepath.Join(tmpdir, dirname), 0o755)
9191
require.NoError(t, err)
9292

93-
_, err = s.CreateDir(t.Context(), &orchestrator.VolumeDirCreateRequest{
93+
_, err = s.CreateDir(t.Context(), &orchestrator.CreateDirRequest{
9494
Volume: volumeInfo,
9595
Path: dirname,
9696
})
@@ -105,7 +105,7 @@ func TestDirCreate(t *testing.T) {
105105
err := os.WriteFile(fullPath, []byte("test"), 0o644)
106106
require.NoError(t, err)
107107

108-
_, err = s.CreateDir(t.Context(), &orchestrator.VolumeDirCreateRequest{
108+
_, err = s.CreateDir(t.Context(), &orchestrator.CreateDirRequest{
109109
Volume: volumeInfo,
110110
Path: filename,
111111
CreateParents: true,
@@ -133,7 +133,7 @@ func TestDirCreate(t *testing.T) {
133133

134134
// Now call CreateDir with CreateParents=true and a different mode
135135
newMode := uint32(0o777)
136-
request := &orchestrator.VolumeDirCreateRequest{
136+
request := &orchestrator.CreateDirRequest{
137137
Volume: volumeInfo,
138138
Path: dirname,
139139
CreateParents: true,

packages/orchestrator/pkg/volumes/dir_delete.go

Lines changed: 0 additions & 67 deletions
This file was deleted.

packages/orchestrator/pkg/volumes/dir_delete_test.go

Lines changed: 0 additions & 72 deletions
This file was deleted.

packages/orchestrator/pkg/volumes/dir_list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const (
2525

2626
func (s *Service) ListDir(
2727
ctx context.Context,
28-
request *orchestrator.VolumeDirListRequest,
29-
) (r *orchestrator.VolumeDirListResponse, err error) {
28+
request *orchestrator.ListDirRequest,
29+
) (r *orchestrator.ListDirResponse, err error) {
3030
ctx, span := tracer.Start(ctx, "list directory in volume")
3131
defer func() {
3232
setSpanStatus(span, err)
@@ -70,7 +70,7 @@ func (s *Service) ListDir(
7070
return nil, fmt.Errorf("failed to read directory %q: %w", path, err)
7171
}
7272

73-
return &orchestrator.VolumeDirListResponse{Files: results}, nil
73+
return &orchestrator.ListDirResponse{Files: results}, nil
7474
}
7575

7676
func (s *Service) listRecursive(

packages/orchestrator/pkg/volumes/dir_list_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestListDir_Depth(t *testing.T) {
4040
t.Run("depth 0", func(t *testing.T) {
4141
t.Parallel()
4242

43-
req := &orchestrator.VolumeDirListRequest{
43+
req := &orchestrator.ListDirRequest{
4444
Volume: volumeInfo,
4545
Path: "dir",
4646
Depth: 0,
@@ -56,7 +56,7 @@ func TestListDir_Depth(t *testing.T) {
5656
t.Run("depth 1", func(t *testing.T) {
5757
t.Parallel()
5858

59-
req := &orchestrator.VolumeDirListRequest{
59+
req := &orchestrator.ListDirRequest{
6060
Volume: volumeInfo,
6161
Path: "dir",
6262
Depth: 1,
@@ -72,7 +72,7 @@ func TestListDir_Depth(t *testing.T) {
7272
t.Run("depth 2", func(t *testing.T) {
7373
t.Parallel()
7474

75-
req := &orchestrator.VolumeDirListRequest{
75+
req := &orchestrator.ListDirRequest{
7676
Volume: volumeInfo,
7777
Path: "dir",
7878
Depth: 2,
@@ -88,7 +88,7 @@ func TestListDir_Depth(t *testing.T) {
8888
t.Run("list non-existent dir", func(t *testing.T) {
8989
t.Parallel()
9090

91-
req := &orchestrator.VolumeDirListRequest{
91+
req := &orchestrator.ListDirRequest{
9292
Volume: volumeInfo,
9393
Path: "non-existent-dir",
9494
}
@@ -99,7 +99,7 @@ func TestListDir_Depth(t *testing.T) {
9999
t.Run("list depth out of range", func(t *testing.T) {
100100
t.Parallel()
101101

102-
req := &orchestrator.VolumeDirListRequest{
102+
req := &orchestrator.ListDirRequest{
103103
Volume: volumeInfo,
104104
Path: "dir",
105105
Depth: 11,

packages/orchestrator/pkg/volumes/file_create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ func (s *Service) CreateFile(server orchestrator.VolumeService_CreateFileServer)
8686
}
8787

8888
switch m := req.GetMessage().(type) {
89-
case *orchestrator.VolumeFileCreateRequest_Content:
89+
case *orchestrator.CreateFileRequest_Content:
9090
if _, err := file.Write(m.Content.GetContent()); err != nil {
9191
return fmt.Errorf("failed to write file content: %w", err)
9292
}
9393

94-
case *orchestrator.VolumeFileCreateRequest_Finish:
94+
case *orchestrator.CreateFileRequest_Finish:
9595
if err = file.Sync(); err != nil {
9696
return fmt.Errorf("failed to sync file to disk: %w", err)
9797
}
@@ -112,7 +112,7 @@ func (s *Service) CreateFile(server orchestrator.VolumeService_CreateFileServer)
112112

113113
entry := toEntry(path, fi)
114114

115-
return server.SendAndClose(&orchestrator.VolumeFileCreateResponse{
115+
return server.SendAndClose(&orchestrator.CreateFileResponse{
116116
Entry: entry,
117117
})
118118

0 commit comments

Comments
 (0)