From 91869fb79bd6ff3bed31d4fdd2dcf57ba1587588 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 14 Jan 2016 13:45:48 -0800 Subject: [PATCH] Added some docs and removed a redundant method --- client/alloc_runner.go | 4 ---- client/allocdir/alloc_dir.go | 10 ++++++++-- client/client.go | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/client/alloc_runner.go b/client/alloc_runner.go index 1a6fd639b0e..71de749c78d 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -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 -} diff --git a/client/allocdir/alloc_dir.go b/client/allocdir/alloc_dir.go index ddefdde0f49..ad7f5738990 100644 --- a/client/allocdir/alloc_dir.go +++ b/client/allocdir/alloc_dir.go @@ -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) @@ -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) @@ -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 } diff --git a/client/client.go b/client/client.go index 5e2d220662c..b7a88c2338f 100644 --- a/client/client.go +++ b/client/client.go @@ -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 }