mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 19:05:42 +03:00
Added the Stat API
This commit is contained in:
@@ -428,3 +428,7 @@ func (r *AllocRunner) WaitCh() <-chan struct{} {
|
||||
func (r *AllocRunner) FSList(path string) ([]*allocdir.AllocFile, error) {
|
||||
return r.ctx.AllocDir.FSList(path)
|
||||
}
|
||||
|
||||
func (r *AllocRunner) FSStat(path string) (*allocdir.AllocFile, error) {
|
||||
return r.ctx.AllocDir.FSStat(path)
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ type AllocDir struct {
|
||||
type AllocFile struct {
|
||||
Name string
|
||||
IsDir bool
|
||||
Size int64
|
||||
}
|
||||
|
||||
func NewAllocDir(allocDir string) *AllocDir {
|
||||
@@ -233,11 +234,26 @@ func (d *AllocDir) FSList(path string) ([]*AllocFile, error) {
|
||||
files[idx] = &AllocFile{
|
||||
Name: info.Name(),
|
||||
IsDir: info.IsDir(),
|
||||
Size: info.Size(),
|
||||
}
|
||||
}
|
||||
return files, err
|
||||
}
|
||||
|
||||
func (d *AllocDir) FSStat(path string) (*AllocFile, error) {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &AllocFile{
|
||||
Size: info.Size(),
|
||||
Name: info.Name(),
|
||||
IsDir: info.IsDir(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func fileCopy(src, dst string, perm os.FileMode) error {
|
||||
// Do a simple copy.
|
||||
srcFile, err := os.Open(src)
|
||||
|
||||
@@ -363,6 +363,14 @@ func (c *Client) FSList(allocID string, path string) ([]*allocdir.AllocFile, err
|
||||
return ar.FSList(path)
|
||||
}
|
||||
|
||||
func (c *Client) FSStat(allocID string, path string) (*allocdir.AllocFile, error) {
|
||||
ar, ok := c.allocs[allocID]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("alloc not found")
|
||||
}
|
||||
return ar.FSStat(path)
|
||||
}
|
||||
|
||||
// restoreState is used to restore our state from the data dir
|
||||
func (c *Client) restoreState() error {
|
||||
if c.config.DevMode {
|
||||
|
||||
@@ -24,7 +24,21 @@ func (s *HTTPServer) DirectoryListRequest(resp http.ResponseWriter, req *http.Re
|
||||
}
|
||||
|
||||
func (s *HTTPServer) FileStatRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
return nil, nil
|
||||
allocID := strings.TrimPrefix(req.URL.Path, "/v1/client/fs/ls/")
|
||||
path := req.URL.Query().Get("path")
|
||||
if path == "" {
|
||||
resp.WriteHeader(http.StatusNotFound)
|
||||
return nil, fmt.Errorf("must provide a file name")
|
||||
}
|
||||
if allocID == "" {
|
||||
resp.WriteHeader(http.StatusNotFound)
|
||||
return nil, fmt.Errorf("alloc id not found")
|
||||
}
|
||||
fileInfo, err := s.agent.client.FSStat(allocID, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fileInfo, nil
|
||||
}
|
||||
|
||||
func (s *HTTPServer) FileReadAtRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
|
||||
Reference in New Issue
Block a user