Skip to content

Commit

Permalink
Merge pull request #376 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.73.2
  • Loading branch information
andyone authored Jul 31, 2023
2 parents 383367a + e9e8573 commit f22c744
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

### 12.73.2

* `[fmtutil]` Fixed handling negative numbers in `PrettySize`
* `[fsutil]` Fixed handling empty paths in `ProperPath`

### 12.73.1

* `[panel]` Panel rendering moved from `terminal` sub-package to it's own sub-package
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.73.1"
const VERSION = "12.73.2"

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

Expand Down
16 changes: 8 additions & 8 deletions fmtutil/fmtutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const (
// ////////////////////////////////////////////////////////////////////////////////// //

const (
_KILO = 1024
_MEGA = 1048576
_GIGA = 1073741824
_TERA = 1099511627776
_KILO float64 = 1024
_MEGA float64 = 1048576
_GIGA float64 = 1073741824
_TERA float64 = 1099511627776
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -148,13 +148,13 @@ func PrettySize(i any, separator ...string) string {
}

switch {
case f >= _TERA:
case math.Abs(f) >= _TERA:
return fmt.Sprintf("%g", Float(f/_TERA)) + sep + "TB"
case f >= _GIGA:
case math.Abs(f) >= _GIGA:
return fmt.Sprintf("%g", Float(f/_GIGA)) + sep + "GB"
case f >= _MEGA:
case math.Abs(f) >= _MEGA:
return fmt.Sprintf("%g", Float(f/_MEGA)) + sep + "MB"
case f >= _KILO:
case math.Abs(f) >= _KILO:
return fmt.Sprintf("%g", Float(f/_KILO)) + sep + "KB"
default:
return fmt.Sprintf("%g", mathutil.Round(f, 0)) + sep + "B"
Expand Down
1 change: 1 addition & 0 deletions fmtutil/fmtutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (s *FmtUtilSuite) TestPretySize(c *C) {
c.Assert(PrettySize(1024*1024*1024), Equals, "1GB")
c.Assert(PrettySize(int64(1024*1024*1024*1024)), Equals, "1TB")
c.Assert(PrettySize(1052500000), Equals, "1003.7MB")
c.Assert(PrettySize(-1052500000), Equals, "-1003.75MB")

c.Assert(PrettySize(int32(3000125)), Equals, "2.86MB")
c.Assert(PrettySize(int64(3000125)), Equals, "2.86MB")
Expand Down
23 changes: 13 additions & 10 deletions fsutil/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ var ErrEmptyPath = errors.New("Path is empty")

// CheckPerms checks many props at once
//
// * F - is file
// * D - is directory
// * X - is executable
// * L - is link
// * W - is writable
// * R - is readable
// * B - is block device
// * C - is character device
// * S - not empty (only for files)
//
// - F: is file
// - D: is directory
// - X: is executable
// - L: is link
// - W: is writable
// - R: is readable
// - B: is block device
// - C: is character device
// - S: not empty (only for files)
func CheckPerms(props, path string) bool {
if props == "" || path == "" {
return false
Expand Down Expand Up @@ -242,6 +241,10 @@ func ValidatePerms(props, path string) error {
// ProperPath returns the first proper path from a given slice
func ProperPath(props string, paths []string) string {
for _, path := range paths {
if strings.Trim(path, " ") == "" {
continue
}

path = PATH.Clean(path)

if CheckPerms(props, path) {
Expand Down
2 changes: 1 addition & 1 deletion fsutil/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (s *FSSuite) TestProperPath(c *check.C) {

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

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

c.Assert(ProperPath("DR", paths), check.Equals, "/etc")
c.Assert(ProperPath("FR", paths), check.Equals, "/etc/passwd")
Expand Down

0 comments on commit f22c744

Please sign in to comment.