-
Notifications
You must be signed in to change notification settings - Fork 6
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 #525 from essentialkaos/develop
Version 13.14.1
- Loading branch information
Showing
11 changed files
with
428 additions
and
336 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
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,69 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package path | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2024 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
import "strings" | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// unsafePaths is slice with unsafe paths | ||
var unsafePaths = []string{ | ||
"/lost+found", | ||
"/bin", | ||
"/boot", | ||
"/etc", | ||
"/dev", | ||
"/lib", | ||
"/lib64", | ||
"/proc", | ||
"/root", | ||
"/sbin", | ||
"/selinux", | ||
"/sys", | ||
"/usr/bin", | ||
"/usr/lib", | ||
"/usr/lib64", | ||
"/usr/libexec", | ||
"/usr/sbin", | ||
"/usr/include", | ||
"/var/cache", | ||
"/var/db", | ||
"/var/lib", | ||
} | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// DirN returns first N elements of path | ||
func DirN(path string, n int) string { | ||
if strings.Count(path, pathSeparator) < 2 || n == 0 { | ||
return path | ||
} | ||
|
||
if n > 0 { | ||
return dirNRight(path, n) | ||
} | ||
|
||
return dirNLeft(path, n*-1) | ||
} | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
func isSafePath(path string) bool { | ||
for _, p := range unsafePaths { | ||
if strings.HasPrefix(path, p) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // |
Oops, something went wrong.