aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/fs/os.go43
-rw-r--r--utils/fs/os_test.go10
2 files changed, 24 insertions, 29 deletions
diff --git a/utils/fs/os.go b/utils/fs/os.go
index 40942ba..1ae4204 100644
--- a/utils/fs/os.go
+++ b/utils/fs/os.go
@@ -7,26 +7,21 @@ import (
"path/filepath"
)
-// NewOS returns a new OS.
-func NewOS() Filesystem {
- return &OSClient{}
-}
-
// OSClient a filesystem based on OSClient
-type OSClient struct {
+type OS struct {
RootDir string
}
// NewOSClient returns a new OSClient
-func NewOSClient(rootDir string) *OSClient {
- return &OSClient{
+func NewOS(rootDir string) *OS {
+ return &OS{
RootDir: rootDir,
}
}
// Create creates a new GlusterFSFile
-func (c *OSClient) Create(filename string) (File, error) {
- fullpath := path.Join(c.RootDir, filename)
+func (fs *OS) Create(filename string) (File, error) {
+ fullpath := path.Join(fs.RootDir, filename)
dir := filepath.Dir(fullpath)
if dir != "." {
@@ -48,8 +43,8 @@ func (c *OSClient) Create(filename string) (File, error) {
// ReadDir returns the filesystem info for all the archives under the specified
// path.
-func (c *OSClient) ReadDir(path string) ([]FileInfo, error) {
- fullpath := c.Join(c.RootDir, path)
+func (fs *OS) ReadDir(path string) ([]FileInfo, error) {
+ fullpath := fs.Join(fs.RootDir, path)
l, err := ioutil.ReadDir(fullpath)
if err != nil {
@@ -64,20 +59,20 @@ func (c *OSClient) ReadDir(path string) ([]FileInfo, error) {
return s, nil
}
-func (c *OSClient) Rename(from, to string) error {
+func (fs *OS) Rename(from, to string) error {
if !filepath.IsAbs(from) {
- from = c.Join(c.RootDir, from)
+ from = fs.Join(fs.RootDir, from)
}
if !filepath.IsAbs(to) {
- to = c.Join(c.RootDir, to)
+ to = fs.Join(fs.RootDir, to)
}
return os.Rename(from, to)
}
-func (c *OSClient) Open(filename string) (File, error) {
- fullpath := c.Join(c.RootDir, filename)
+func (fs *OS) Open(filename string) (File, error) {
+ fullpath := fs.Join(fs.RootDir, filename)
f, err := os.Open(fullpath)
if err != nil {
@@ -90,22 +85,22 @@ func (c *OSClient) Open(filename string) (File, error) {
}, nil
}
-func (c *OSClient) Stat(filename string) (FileInfo, error) {
- fullpath := c.Join(c.RootDir, filename)
+func (fs *OS) Stat(filename string) (FileInfo, error) {
+ fullpath := fs.Join(fs.RootDir, filename)
return os.Stat(fullpath)
}
// Join joins the specified elements using the filesystem separator.
-func (c *OSClient) Join(elem ...string) string {
+func (fs *OS) Join(elem ...string) string {
return filepath.Join(elem...)
}
-func (c *OSClient) Dir(path string) Filesystem {
- return NewOSClient(c.Join(c.RootDir, path))
+func (fs *OS) Dir(path string) Filesystem {
+ return NewOS(fs.Join(fs.RootDir, path))
}
-func (c *OSClient) Base() string {
- return c.RootDir
+func (fs *OS) Base() string {
+ return fs.RootDir
}
type OSFile struct {
diff --git a/utils/fs/os_test.go b/utils/fs/os_test.go
index c148265..acc6bdd 100644
--- a/utils/fs/os_test.go
+++ b/utils/fs/os_test.go
@@ -16,16 +16,16 @@ var _ = Suite(&WritersSuite{})
func (s *WritersSuite) TestOSClient_Create(c *C) {
path := getTempDir()
- client := NewOSClient(path)
+ client := NewOS(path)
f, err := client.Create("foo")
c.Assert(err, IsNil)
- c.Assert(f.(*OSFile).file.Name(), Equals, f.GetFilename())
+ c.Assert(f.(*OSFile).file.Name(), Equals, f.Filename())
}
func (s *WritersSuite) TestOSClient_Write(c *C) {
path := getTempDir()
- client := NewOSClient(path)
+ client := NewOS(path)
f, err := client.Create("foo")
c.Assert(err, IsNil)
@@ -39,14 +39,14 @@ func (s *WritersSuite) TestOSClient_Write(c *C) {
func (s *WritersSuite) TestOSClient_Close(c *C) {
path := getTempDir()
- client := NewOSClient(path)
+ client := NewOS(path)
f, err := client.Create("foo")
c.Assert(err, IsNil)
f.Write([]byte("foo"))
c.Assert(f.Close(), IsNil)
- wrote, _ := ioutil.ReadFile(f.GetFilename())
+ wrote, _ := ioutil.ReadFile(f.Filename())
c.Assert(wrote, DeepEquals, []byte("foo"))
}