Implemented the Stat API

This commit is contained in:
Diptanu Choudhury
2016-01-12 21:28:07 -08:00
parent cbcdaec3fe
commit b5385b616d
3 changed files with 17 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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)