aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-09-25 23:58:59 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-09-25 23:58:59 +0200
commitb9c0a09435392913c0054382500c805cd7cb596b (patch)
treed5a4bebff33b02215b25515ab769f277c0c07bb9 /utils
parent859775d320d574979c63a114de1437e3c5d9114c (diff)
downloadgo-git-b9c0a09435392913c0054382500c805cd7cb596b.tar.gz
formats: objfile idomatic reader/writer
Diffstat (limited to 'utils')
-rw-r--r--utils/fs/os.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/utils/fs/os.go b/utils/fs/os.go
index 51af921..a0d197d 100644
--- a/utils/fs/os.go
+++ b/utils/fs/os.go
@@ -23,11 +23,8 @@ func NewOS(rootDir string) *OS {
func (fs *OS) Create(filename string) (File, error) {
fullpath := path.Join(fs.RootDir, filename)
- dir := filepath.Dir(fullpath)
- if dir != "." {
- if err := os.MkdirAll(dir, 0755); err != nil {
- return nil, err
- }
+ if err := fs.createDir(fullpath); err != nil {
+ return nil, err
}
f, err := os.Create(fullpath)
@@ -41,6 +38,17 @@ func (fs *OS) Create(filename string) (File, error) {
}, nil
}
+func (fs *OS) createDir(fullpath string) error {
+ dir := filepath.Dir(fullpath)
+ if dir != "." {
+ if err := os.MkdirAll(dir, 0755); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
// ReadDir returns the filesystem info for all the archives under the specified
// path.
func (fs *OS) ReadDir(path string) ([]FileInfo, error) {
@@ -62,6 +70,11 @@ func (fs *OS) ReadDir(path string) ([]FileInfo, error) {
func (fs *OS) Rename(from, to string) error {
from = fs.Join(fs.RootDir, from)
to = fs.Join(fs.RootDir, to)
+
+ if err := fs.createDir(to); err != nil {
+ return err
+ }
+
return os.Rename(from, to)
}