-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
require a minimal filesystem interface
- Loading branch information
Showing
7 changed files
with
90 additions
and
63 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/tsuru/tsuru/fs" | ||
) | ||
|
||
type Filesystem interface { | ||
ReadFile(name string) ([]byte, error) | ||
CheckFile(name string) (bool, error) | ||
RemoveFile(name string) error | ||
} | ||
|
||
// localFS is a wrapper around fs.Fs that implements Filesystem | ||
type localFS struct{ fs.Fs } | ||
|
||
func (f *localFS) ReadFile(name string) ([]byte, error) { | ||
file, err := f.Fs.Open(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
return ioutil.ReadAll(file) | ||
} | ||
|
||
func (f *localFS) CheckFile(name string) (bool, error) { | ||
_, err := f.Fs.Stat(name) | ||
if os.IsNotExist(err) { | ||
return false, nil | ||
} | ||
return err == nil, err | ||
} | ||
|
||
func (f *localFS) RemoveFile(name string) error { | ||
return f.Fs.Remove(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters