Skip to content

Commit 39aa907

Browse files
committed
dean review
1 parent 69443ce commit 39aa907

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

agent/ls.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func (*agent) HandleLS(rw http.ResponseWriter, r *http.Request) {
1919
ctx := r.Context()
2020

21-
var query LSQuery
21+
var query LSRequest
2222
if !httpapi.Read(ctx, rw, r, &query) {
2323
return
2424
}
@@ -45,7 +45,7 @@ func (*agent) HandleLS(rw http.ResponseWriter, r *http.Request) {
4545
httpapi.Write(ctx, rw, http.StatusOK, resp)
4646
}
4747

48-
func listFiles(query LSQuery) (LSResponse, error) {
48+
func listFiles(query LSRequest) (LSResponse, error) {
4949
var fullPath []string
5050
switch query.Relativity {
5151
case LSRelativityHome:
@@ -67,28 +67,29 @@ func listFiles(query LSQuery) (LSResponse, error) {
6767
}
6868

6969
fullPath = append(fullPath, query.Path...)
70-
absolutePathString, err := filepath.Abs(filepath.Join(fullPath...))
70+
fullPathRelative := filepath.Join(fullPath...)
71+
absolutePathString, err := filepath.Abs(fullPathRelative)
7172
if err != nil {
72-
return LSResponse{}, xerrors.Errorf("failed to get absolute path: %w", err)
73+
return LSResponse{}, xerrors.Errorf("failed to get absolute path of %q: %w", fullPathRelative, err)
7374
}
7475

7576
f, err := os.Open(absolutePathString)
7677
if err != nil {
77-
return LSResponse{}, xerrors.Errorf("failed to open directory: %w", err)
78+
return LSResponse{}, xerrors.Errorf("failed to open directory %q: %w", absolutePathString, err)
7879
}
7980
defer f.Close()
8081

8182
stat, err := f.Stat()
8283
if err != nil {
83-
return LSResponse{}, xerrors.Errorf("failed to stat directory: %w", err)
84+
return LSResponse{}, xerrors.Errorf("failed to stat directory %q: %w", absolutePathString, err)
8485
}
8586

8687
if !stat.IsDir() {
87-
return LSResponse{}, xerrors.New("path is not a directory")
88+
return LSResponse{}, xerrors.Errorf("path %q is not a directory", absolutePathString)
8889
}
8990

9091
// `contents` may be partially populated even if the operation fails midway.
91-
contents, _ := f.Readdir(-1)
92+
contents, _ := f.ReadDir(-1)
9293
respContents := make([]LSFile, 0, len(contents))
9394
for _, file := range contents {
9495
respContents = append(respContents, LSFile{
@@ -140,7 +141,7 @@ func pathToArray(path string) []string {
140141
return out
141142
}
142143

143-
type LSQuery struct {
144+
type LSRequest struct {
144145
// e.g. [], ["repos", "coder"],
145146
Path []string `json:"path"`
146147
// Whether the supplied path is relative to the user's home directory,

agent/ls_internal_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestListFilesNonExistentDirectory(t *testing.T) {
1313
t.Parallel()
1414

15-
query := LSQuery{
15+
query := LSRequest{
1616
Path: []string{"idontexist"},
1717
Relativity: LSRelativityHome,
1818
}
@@ -39,7 +39,7 @@ func TestListFilesPermissionDenied(t *testing.T) {
3939
rel, err := filepath.Rel(home, reposDir)
4040
require.NoError(t, err)
4141

42-
query := LSQuery{
42+
query := LSRequest{
4343
Path: pathToArray(rel),
4444
Relativity: LSRelativityHome,
4545
}
@@ -62,12 +62,12 @@ func TestListFilesNotADirectory(t *testing.T) {
6262
rel, err := filepath.Rel(home, filePath)
6363
require.NoError(t, err)
6464

65-
query := LSQuery{
65+
query := LSRequest{
6666
Path: pathToArray(rel),
6767
Relativity: LSRelativityHome,
6868
}
6969
_, err = listFiles(query)
70-
require.ErrorContains(t, err, "path is not a directory")
70+
require.ErrorContains(t, err, "is not a directory")
7171
}
7272

7373
func TestListFilesSuccess(t *testing.T) {
@@ -125,7 +125,7 @@ func TestListFilesSuccess(t *testing.T) {
125125
queryComponents = pathToArray(rel)
126126
}
127127

128-
query := LSQuery{
128+
query := LSRequest{
129129
Path: queryComponents,
130130
Relativity: tc.relativity,
131131
}
@@ -161,7 +161,7 @@ func TestListFilesListDrives(t *testing.T) {
161161
t.Skip("skipping test on non-Windows OS")
162162
}
163163

164-
query := LSQuery{
164+
query := LSRequest{
165165
Path: []string{},
166166
Relativity: LSRelativityRoot,
167167
}
@@ -173,14 +173,14 @@ func TestListFilesListDrives(t *testing.T) {
173173
IsDir: true,
174174
})
175175

176-
query = LSQuery{
176+
query = LSRequest{
177177
Path: []string{"C:\\"},
178178
Relativity: LSRelativityRoot,
179179
}
180180
resp, err = listFiles(query)
181181
require.NoError(t, err)
182182

183-
query = LSQuery{
183+
query = LSRequest{
184184
Path: resp.AbsolutePath,
185185
Relativity: LSRelativityRoot,
186186
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy