Skip to content

Commit 16eea2b

Browse files
committed
Adds the Lsdir API to the Filesystem V1 API Group
1 parent 4f3e06a commit 16eea2b

File tree

14 files changed

+625
-146
lines changed

14 files changed

+625
-146
lines changed

client/api/filesystem/v1/api.pb.go

Lines changed: 243 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/api/filesystem/v1/api.proto

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ service Filesystem {
1515
// This may be used for unlinking a symlink created through CreateSymlink.
1616
rpc Rmdir(RmdirRequest) returns (RmdirResponse) {}
1717

18+
// Lsdir lists files in a directory
19+
rpc Lsdir(LsdirRequest) returns (LsdirResponse) {}
20+
1821
// CreateSymlink creates a symbolic link called target_path that points to source_path
1922
// in the host filesystem (target_path is the name of the symbolic link created,
2023
// source_path is the existing path).
@@ -86,6 +89,16 @@ message RmdirResponse {
8689
// Intentionally empty.
8790
}
8891

92+
message LsdirRequest {
93+
// The path to list files from.
94+
string path = 1;
95+
}
96+
97+
message LsdirResponse {
98+
// The paths under that directory.
99+
repeated string files = 1;
100+
}
101+
89102
message CreateSymlinkRequest {
90103
// The path of the existing directory to be linked.
91104
// All special characters allowed by Windows in path names will be allowed

client/groups/filesystem/v1/client_generated.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/os/filesystem/api.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type API interface {
1818
PathValid(path string) (bool, error)
1919
Mkdir(path string) error
2020
Rmdir(path string, force bool) error
21+
Lsdir(path string) ([]string, error)
2122
CreateSymlink(oldname string, newname string) error
2223
IsSymlink(path string) (bool, error)
2324
}
@@ -78,6 +79,21 @@ func (filesystemAPI) Rmdir(path string, force bool) error {
7879
return os.Remove(path)
7980
}
8081

82+
// Lsdir lists files under a directory
83+
func (filesystemAPI) Lsdir(path string) ([]string, error) {
84+
dir, err := os.Open(path)
85+
if err != nil {
86+
return nil, err
87+
}
88+
defer dir.Close()
89+
90+
names, err := dir.Readdirnames(-1)
91+
if err != nil {
92+
return nil, err
93+
}
94+
return names, nil
95+
}
96+
8197
// CreateSymlink creates newname as a symbolic link to oldname.
8298
func (filesystemAPI) CreateSymlink(oldname, newname string) error {
8399
return os.Symlink(oldname, newname)

pkg/server/filesystem/impl/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ type RmdirRequest struct {
6161
type RmdirResponse struct {
6262
}
6363

64+
type LsdirRequest struct {
65+
// The directory to list files from.
66+
Path string
67+
}
68+
69+
type LsdirResponse struct {
70+
// The files under the directory.
71+
Files []string
72+
}
73+
6474
type CreateSymlinkRequest struct {
6575
// The path of the existing directory to be linked.
6676
// All special characters allowed by Windows in path names will be allowed

pkg/server/filesystem/impl/types_generated.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/server/filesystem/impl/v1/conversion_generated.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/server/filesystem/impl/v1/server_generated.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/server/filesystem/server.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ func (s *Server) LinkPath(ctx context.Context, request *internal.LinkPathRequest
167167
return &internal.LinkPathResponse{}, nil
168168
}
169169

170+
func (s *Server) Lsdir(ctx context.Context, request *internal.LsdirRequest, version apiversion.Version) (*internal.LsdirResponse, error) {
171+
klog.V(2).Infof("Request: Lsdir with path=%q", request.Path)
172+
err := s.validatePathWindows(request.Path)
173+
if err != nil {
174+
klog.Errorf("failed validatePathWindows for path=%q, err=%v", request.Path, err)
175+
return nil, err
176+
}
177+
names, err := s.hostAPI.Lsdir(request.Path)
178+
return &internal.LsdirResponse{Files: names}, nil
179+
}
180+
170181
func (s *Server) CreateSymlink(ctx context.Context, request *internal.CreateSymlinkRequest, version apiversion.Version) (*internal.CreateSymlinkResponse, error) {
171182
klog.V(2).Infof("Request: CreateSymlink with targetPath=%q sourcePath=%q", request.TargetPath, request.SourcePath)
172183
err := s.validatePathWindows(request.TargetPath)

pkg/server/filesystem/server_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func (fakeFileSystemAPI) Mkdir(path string) error {
2525
func (fakeFileSystemAPI) Rmdir(path string, force bool) error {
2626
return nil
2727
}
28+
func (fakeFileSystemAPI) Lsdir(path string) ([]string, error) {
29+
return nil, nil
30+
}
2831
func (fakeFileSystemAPI) CreateSymlink(tgt string, src string) error {
2932
return nil
3033
}

pkg/server/smb/server_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func (fakeFileSystemAPI) Mkdir(path string) error {
4747
func (fakeFileSystemAPI) Rmdir(path string, force bool) error {
4848
return nil
4949
}
50+
func (fakeFileSystemAPI) Lsdir(path string) ([]string, error) {
51+
return nil, nil
52+
}
5053
func (fakeFileSystemAPI) CreateSymlink(tgt string, src string) error {
5154
return nil
5255
}

0 commit comments

Comments
 (0)