-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from essentialkaos/develop
Version 1.5.0
- Loading branch information
Showing
14 changed files
with
186 additions
and
28 deletions.
There are no files selected for viewing
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,39 @@ | ||
version: "2" | ||
|
||
checks: | ||
argument-count: | ||
enabled: true | ||
config: | ||
threshold: 6 | ||
complex-logic: | ||
enabled: true | ||
config: | ||
threshold: 6 | ||
file-lines: | ||
enabled: true | ||
config: | ||
threshold: 1000 | ||
method-complexity: | ||
enabled: true | ||
config: | ||
threshold: 8 | ||
method-count: | ||
enabled: true | ||
config: | ||
threshold: 20 | ||
method-lines: | ||
enabled: true | ||
config: | ||
threshold: 100 | ||
nested-control-flow: | ||
enabled: true | ||
config: | ||
threshold: 6 | ||
return-statements: | ||
enabled: true | ||
config: | ||
threshold: 6 | ||
similar-code: | ||
enabled: false | ||
identical-code: | ||
enabled: false |
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
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
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,57 @@ | ||
// Package utils provides auxiliary methods for working with archives | ||
package utils | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2023 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// Join joins all elements of path, makes lexical processing, and evaluating all symlinks. | ||
// Method returns error if final destination is not a child path of root. | ||
func Join(root string, elem ...string) (string, error) { | ||
result, err := filepath.EvalSymlinks(root) | ||
|
||
if err != nil { | ||
result = root | ||
} else { | ||
root = result | ||
} | ||
|
||
for _, e := range elem { | ||
result = filepath.Clean(result + "/" + e) | ||
|
||
if isLink(result) { | ||
result, err = filepath.EvalSymlinks(result) | ||
|
||
if err != nil { | ||
return "", fmt.Errorf("Can't eval symlinks: %w", err) | ||
} | ||
} | ||
} | ||
|
||
if !strings.HasPrefix(result, root) { | ||
return "", fmt.Errorf("Final destination (%s) is outside root (%s)", result, root) | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
func isLink(path string) bool { | ||
var buf = make([]byte, 1) | ||
_, err := syscall.Readlink(path, buf) | ||
|
||
return err == nil | ||
} |
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,62 @@ | ||
package utils | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2023 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
. "github.com/essentialkaos/check" | ||
) | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
func Test(t *testing.T) { TestingT(t) } | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
type UtilsSuite struct{} | ||
|
||
var _ = Suite(&UtilsSuite{}) | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
func (s *UtilsSuite) TestJoin(c *C) { | ||
p, err := Join("/test", "myapp") | ||
c.Assert(err, IsNil) | ||
c.Assert(p, Equals, "/test/myapp") | ||
|
||
p, err = Join("/test", "myapp/config/../global.cfg") | ||
c.Assert(err, IsNil) | ||
c.Assert(p, Equals, "/test/myapp/global.cfg") | ||
|
||
p, err = Join("/unknown", "myapp/config/../global.cfg") | ||
c.Assert(err, IsNil) | ||
c.Assert(p, Equals, "/unknown/myapp/global.cfg") | ||
|
||
tmpDir := c.MkDir() | ||
os.Mkdir(tmpDir+"/test", 0755) | ||
os.Symlink(tmpDir+"/test", tmpDir+"/testlink") | ||
testDir := tmpDir + "/testlink" | ||
|
||
os.Symlink(testDir+"/test.log", testDir+"/test1.link") | ||
os.WriteFile(testDir+"/test.log", []byte("\n"), 0644) | ||
os.Symlink(testDir+"/test.log", testDir+"/test1.link") | ||
os.Symlink("/etc", testDir+"/test2.link") | ||
os.Symlink(testDir+"/test3.link", testDir+"/test3.link") | ||
|
||
p, err = Join(testDir, "mytest/../test1.link") | ||
c.Assert(err, IsNil) | ||
c.Assert(p, Matches, "*/test/test.log") | ||
|
||
p, err = Join(testDir, "mytest/../test2.link") | ||
c.Assert(err, NotNil) | ||
|
||
p, err = Join(testDir, "mytest/../test3.link") | ||
c.Assert(err, NotNil) | ||
} |
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