Skip to content

Commit

Permalink
Added some docs and removed a redundant method
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu committed Jan 14, 2016
1 parent 12f44a2 commit 91869fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 0 additions & 4 deletions client/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,3 @@ func (r *AllocRunner) Destroy() {
func (r *AllocRunner) WaitCh() <-chan struct{} {
return r.waitCh
}

func (r *AllocRunner) GetAllocFS(allocID string) allocdir.AllocDirFS {
return r.ctx.AllocDir
}
10 changes: 8 additions & 2 deletions client/allocdir/alloc_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (d *AllocDir) MountSharedDir(task string) error {
return nil
}

// List returns the list of files at a path relative to the alloc dir
func (d *AllocDir) List(path string) ([]*AllocFileInfo, error) {
p := filepath.Join(d.AllocDir, path)
finfos, err := ioutil.ReadDir(p)
Expand All @@ -246,6 +247,7 @@ func (d *AllocDir) List(path string) ([]*AllocFileInfo, error) {
return files, err
}

// Stat returns information about the file at path relative to the alloc dir
func (d *AllocDir) Stat(path string) (*AllocFileInfo, error) {
p := filepath.Join(d.AllocDir, path)
info, err := os.Stat(p)
Expand All @@ -260,16 +262,20 @@ func (d *AllocDir) Stat(path string) (*AllocFileInfo, error) {
}, nil
}

// ReadAt returns a reader for a file at the path relative to the alloc dir
//which will read a chunk of bytes at a particular offset
func (d *AllocDir) ReadAt(path string, offset int64, limit int64) (io.ReadCloser, error) {
p := filepath.Join(d.AllocDir, path)
f, err := os.Open(p)
if err != nil {
return nil, err
}
return &LimitReadCloser{Reader: io.LimitReader(f, limit), Closer: f}, nil
return &FileReadCloser{Reader: io.LimitReader(f, limit), Closer: f}, nil
}

type LimitReadCloser struct {
// FileReadCloser wraps a LimitReader so that a file is closed once it has been
// read
type FileReadCloser struct {
io.Reader
io.Closer
}
Expand Down
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,13 @@ func (c *Client) Node() *structs.Node {
return c.config.Node
}

// GetAllocFS returns the AllocFS interface for the alloc dir of an allocation
func (c *Client) GetAllocFS(allocID string) (allocdir.AllocDirFS, error) {
ar, ok := c.allocs[allocID]
if !ok {
return nil, fmt.Errorf("alloc not found")
}
return ar.GetAllocFS(allocID), nil
return ar.ctx.AllocDir, nil

}

Expand Down

0 comments on commit 91869fb

Please sign in to comment.