Skip to content

Commit

Permalink
Merge pull request #27 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.6.4
  • Loading branch information
andyone committed Feb 10, 2016
2 parents 81750cc + 4348143 commit 3ef12a1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

#### v1.6.4

* `[path]` Added method IsDotfile for checking dotfile names

#### v1.6.3

* `[strutil]` Added methods PrefixSize and SuffixSize
Expand Down
16 changes: 16 additions & 0 deletions path/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"errors"
PATH "path"
"path/filepath"
"strings"

"pkg.re/essentialkaos/ek.v1/env"
)
Expand Down Expand Up @@ -112,6 +113,21 @@ func IsSafe(path string) bool {
return true
}

// IsDotfile return true if file name begins with a full stop
func IsDotfile(path string) bool {
if path == "" {
return false
}

if !strings.Contains(path, "/") {
return path[0:1] == "."
}

pathBase := Base(path)

return pathBase[0:1] == "."
}

// ////////////////////////////////////////////////////////////////////////////////// //

func evalHome(path string) string {
Expand Down
13 changes: 13 additions & 0 deletions path/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,16 @@ func (s *PathUtilSuite) TestSafe(c *C) {
c.Assert(IsSafe("/var/db/yum"), Equals, false)
c.Assert(IsSafe("/var/lib/pgsql"), Equals, false)
}

func (s *PathUtilSuite) TestDotfile(c *C) {
c.Assert(IsDotfile(""), Equals, false)
c.Assert(IsDotfile("/some/dir/abcd"), Equals, false)
c.Assert(IsDotfile("/some/dir/"), Equals, false)
c.Assert(IsDotfile("/"), Equals, false)
c.Assert(IsDotfile("/////"), Equals, false)
c.Assert(IsDotfile(" / "), Equals, false)

c.Assert(IsDotfile(".dotfile"), Equals, true)
c.Assert(IsDotfile("/.dotfile"), Equals, true)
c.Assert(IsDotfile("/some/dir/.abcd"), Equals, true)
}
5 changes: 5 additions & 0 deletions path/path_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ func Split(path string) (dir, file string) {
func IsSafe(path string) bool {
return false
}

// IsDotfile return true if file name begins with a full stop
func IsDotfile(path string) bool {
return false
}

0 comments on commit 3ef12a1

Please sign in to comment.