Skip to content

Commit

Permalink
Merge pull request #14 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.4.2
  • Loading branch information
andyone committed Jan 15, 2016
2 parents e7dc63c + 00ebaed commit cd1a49c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .travis/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ testWithCover() {
# fsutil currently is hard to test
# we test this package by hands
if [[ "$pkg" == "fsutil" ]] ; then
go test $dir/$pkg

if [[ $? -ne 0 ]] ; then
has_errors=true
fi

continue
fi

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

#### v1.4.2

* `[fsutil]` Added method `ProperPath` which return first proper path from given slice

#### v1.4.1

* `[fsutil]` Added partial FreeBSD support
Expand Down
11 changes: 11 additions & 0 deletions fsutil/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ func CheckPerms(props, path string) bool {
return true
}

// ProperPath return first proper path from given slice
func ProperPath(props string, paths []string) string {
for _, path := range paths {
if CheckPerms(props, path) {
return path
}
}

return ""
}

// IsExist check if target is exist in fs or not
func IsExist(path string) bool {
if path == "" {
Expand Down
16 changes: 16 additions & 0 deletions fsutil/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,19 @@ func (fs *FSSuite) TestList(c *check.C) {
[]string{"dir2/file4.wav", "file2.jpg"},
)
}

func (fs *FSSuite) TestProperPath(c *check.C) {
tmpFile := fs.TempDir + "/test.txt"

os.OpenFile(tmpFile, os.O_CREATE, 0644)

paths := []string{"/etc/sudoers", "/etc/passwd", tmpFile}

c.Assert(ProperPath("DR", paths), check.Equals, "")
c.Assert(ProperPath("FR", paths), check.Equals, "/etc/passwd")
c.Assert(ProperPath("FRW", paths), check.Equals, tmpFile)
c.Assert(ProperPath("FRWS", paths), check.Equals, "")
c.Assert(ProperPath("F", paths), check.Equals, "/etc/sudoers")

os.Remove(tmpFile)
}

0 comments on commit cd1a49c

Please sign in to comment.