Skip to content

Commit

Permalink
Merge pull request #28 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.7.0
  • Loading branch information
andyone committed Feb 17, 2016
2 parents 3ef12a1 + ba393e4 commit abb1c47
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
11 changes: 11 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## Changelog

#### v1.7.0

* `[fsutil]` Fixed major bug with closing file descriptor after directory listing
* `[fsutil]` Fixed major bug with closing file descriptor after counting lines in file
* `[fsutil]` Fixed major bug with closing file descriptor after checking number of files in directory

#### v1.6.5

* `[fsutil]` Improved docs
* `[fsutil]` Added method (wrapper) for moving files

#### v1.6.4

* `[path]` Added method IsDotfile for checking dotfile names
Expand Down
15 changes: 15 additions & 0 deletions fsutil/copy.go → fsutil/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,18 @@ func CopyFile(from, to string, perms ...os.FileMode) error {

return err
}

// MoveFile move file
func MoveFile(from, to string, perms ...os.FileMode) error {
err := os.Rename(from, to)

if err != nil {
return err
}

if len(perms) == 0 {
return nil
}

return os.Chmod(to, perms[0])
}
13 changes: 12 additions & 1 deletion fsutil/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ const (

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

// CheckPerms check many props at once
// CheckPerms check many props at once.
//
// F - is file
// D - is directory
// X - is executable
// L - is link
// W - is writable
// R - is readable
// S - not empty (only for files)
//
func CheckPerms(props, path string) bool {
if len(props) == 0 || path == "" {
return false
Expand Down Expand Up @@ -326,6 +335,8 @@ func IsEmptyDir(path string) bool {
return false
}

defer syscall.Close(fd)

n, err := syscall.ReadDirent(fd, make([]byte, 4096))

if n == 0x30 || err != nil {
Expand Down
2 changes: 2 additions & 0 deletions fsutil/line_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func LineCount(file string) int {
return -1
}

defer fd.Close()

// Use 32k buffer
buf := make([]byte, 32*1024)
count := 0
Expand Down
2 changes: 2 additions & 0 deletions fsutil/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func readDir(dir string) []string {
return []string{}
}

defer syscall.Close(fd)

var size = 100
var n = -1

Expand Down

0 comments on commit abb1c47

Please sign in to comment.