Skip to content

Commit 369852c

Browse files
committed
undo ls on file
1 parent b1e414f commit 369852c

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

agent/ls.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func listFiles(query LSRequest) (LSResponse, error) {
7575
if err != nil {
7676
return LSResponse{}, xerrors.Errorf("failed to get absolute path of %q: %w", fullPathRelative, err)
7777
}
78-
absolutePath := pathToArray(absolutePathString)
7978

8079
f, err := os.Open(absolutePathString)
8180
if err != nil {
@@ -89,18 +88,7 @@ func listFiles(query LSRequest) (LSResponse, error) {
8988
}
9089

9190
if !stat.IsDir() {
92-
// `ls` on a file should return just that file.
93-
return LSResponse{
94-
AbsolutePath: absolutePath,
95-
AbsolutePathString: absolutePathString,
96-
Contents: []LSFile{
97-
{
98-
Name: filepath.Base(f.Name()),
99-
AbsolutePathString: absolutePathString,
100-
IsDir: false,
101-
},
102-
},
103-
}, nil
91+
return LSResponse{}, xerrors.Errorf("path %q is not a directory", absolutePathString)
10492
}
10593

10694
// `contents` may be partially populated even if the operation fails midway.
@@ -114,6 +102,8 @@ func listFiles(query LSRequest) (LSResponse, error) {
114102
})
115103
}
116104

105+
absolutePath := pathToArray(absolutePathString)
106+
117107
return LSResponse{
118108
AbsolutePath: absolutePath,
119109
AbsolutePathString: absolutePathString,

agent/ls_internal_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,8 @@ func TestListFilesNotADirectory(t *testing.T) {
6666
Path: pathToArray(rel),
6767
Relativity: LSRelativityHome,
6868
}
69-
resp, err := listFiles(query)
70-
require.NoError(t, err)
71-
require.Equal(t, filePath, resp.AbsolutePathString)
72-
require.ElementsMatch(t, []LSFile{
73-
{
74-
Name: "file.txt",
75-
AbsolutePathString: filePath,
76-
IsDir: false,
77-
},
78-
}, resp.Contents)
69+
_, err = listFiles(query)
70+
require.ErrorContains(t, err, "is not a directory")
7971
}
8072

8173
func TestListFilesSuccess(t *testing.T) {

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