Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion adk/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,15 @@ func (s *Local) LsInfo(ctx context.Context, req *filesystem.LsInfoRequest) ([]fi

var files []filesystem.FileInfo
for _, entry := range entries {
info, err := entry.Info()
if err != nil {
return nil, fmt.Errorf("failed to get info of %s: %w", entry.Name(), err)
}
files = append(files, filesystem.FileInfo{
Path: entry.Name(),
Path: entry.Name(),
IsDir: entry.IsDir(),
Size: info.Size(),
ModifiedAt: info.ModTime().Format(time.RFC3339Nano),
})
}

Expand Down
32 changes: 31 additions & 1 deletion adk/backend/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -51,15 +52,44 @@ func TestLsInfo(t *testing.T) {
defer os.RemoveAll(dir)

// Create test files and directories
assert.NoError(t, os.WriteFile(filepath.Join(dir, "file1.txt"), []byte(""), 0644))
assert.NoError(t, os.WriteFile(filepath.Join(dir, "file1.txt"), []byte("hello"), 0644))
assert.NoError(t, os.Mkdir(filepath.Join(dir, "subdir"), 0755))

req := &filesystem.LsInfoRequest{Path: dir}
files, err := s.LsInfo(ctx, req)
assert.NoError(t, err)
assert.Len(t, files, 2)
assert.Equal(t, "file1.txt", files[0].Path)
assert.False(t, files[0].IsDir)
assert.Equal(t, int64(len("hello")), files[0].Size)
_, err = time.Parse(time.RFC3339Nano, files[0].ModifiedAt)
assert.NoError(t, err)
assert.Equal(t, "subdir", files[1].Path)
assert.True(t, files[1].IsDir)
_, err = time.Parse(time.RFC3339Nano, files[1].ModifiedAt)
assert.NoError(t, err)
})

t.Run("symlink entries report the link itself", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("creating symlinks on windows requires privileges")
}

dir := setupTestDir(t)
defer os.RemoveAll(dir)

assert.NoError(t, os.WriteFile(filepath.Join(dir, "target.txt"), []byte("hello"), 0644))
assert.NoError(t, os.Symlink("target.txt", filepath.Join(dir, "link.txt")))

req := &filesystem.LsInfoRequest{Path: dir}
files, err := s.LsInfo(ctx, req)
assert.NoError(t, err)
assert.Len(t, files, 2)
assert.Equal(t, "link.txt", files[0].Path)
assert.False(t, files[0].IsDir)
assert.Equal(t, int64(len("target.txt")), files[0].Size)
assert.Equal(t, "target.txt", files[1].Path)
assert.False(t, files[1].IsDir)
})

t.Run("list non-existent directory", func(t *testing.T) {
Expand Down
Loading