From b5385b616d7978e7e01e7f3c5722de66ec5ef030 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Tue, 12 Jan 2016 21:28:07 -0800 Subject: [PATCH] Implemented the Stat API --- client/allocdir/alloc_dir.go | 13 ++++++++++++- client/client.go | 4 ++++ command/agent/fs_endpoint.go | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client/allocdir/alloc_dir.go b/client/allocdir/alloc_dir.go index 19a26fd9c..589a77d55 100644 --- a/client/allocdir/alloc_dir.go +++ b/client/allocdir/alloc_dir.go @@ -241,7 +241,8 @@ func (d *AllocDir) FSList(path string) ([]*AllocFile, error) { } func (d *AllocDir) FSStat(path string) (*AllocFile, error) { - info, err := os.Stat(path) + p := filepath.Join(d.AllocDir, path) + info, err := os.Stat(p) if err != nil { return nil, err } @@ -251,7 +252,17 @@ func (d *AllocDir) FSStat(path string) (*AllocFile, error) { Name: info.Name(), IsDir: info.IsDir(), }, nil +} +func (d *AllocDir) FSReadAt(allocID string, path string, offset int64, limit int64) ([]byte, error) { + p := filepath.Join(d.AllocDir, path) + f, err := os.Open(p) + if err != nil { + return nil, err + } + b := make([]byte, limit) + f.ReadAt(b, offset) + return b, nil } func fileCopy(src, dst string, perm os.FileMode) error { diff --git a/client/client.go b/client/client.go index f7ae52682..f7a526c09 100644 --- a/client/client.go +++ b/client/client.go @@ -371,6 +371,10 @@ func (c *Client) FSStat(allocID string, path string) (*allocdir.AllocFile, error return ar.FSStat(path) } +func (c *Client) FSReadAt(allocID string, path string, offset int64, limit int64) ([]byte, error) { + return nil, nil +} + // restoreState is used to restore our state from the data dir func (c *Client) restoreState() error { if c.config.DevMode { diff --git a/command/agent/fs_endpoint.go b/command/agent/fs_endpoint.go index 58dd1e5ab..a4fd48cb3 100644 --- a/command/agent/fs_endpoint.go +++ b/command/agent/fs_endpoint.go @@ -24,7 +24,7 @@ func (s *HTTPServer) DirectoryListRequest(resp http.ResponseWriter, req *http.Re } func (s *HTTPServer) FileStatRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { - allocID := strings.TrimPrefix(req.URL.Path, "/v1/client/fs/ls/") + allocID := strings.TrimPrefix(req.URL.Path, "/v1/client/fs/stat/") path := req.URL.Query().Get("path") if path == "" { resp.WriteHeader(http.StatusNotFound)