mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Implemented the Stat API
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user