1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00
This commit is contained in:
Tom Limoncelli
2020-08-26 13:45:02 -04:00
committed by GitHub
parent 57d9cfa356
commit d6dd13820f
5 changed files with 21 additions and 21 deletions

View File

@ -298,7 +298,7 @@ func TestInvalidGlobIgnoredTarget(t *testing.T) {
} }
}() }()
checkLengthsFull(t, existing, desired, 0, 1, 0, 0, false, nil, []*models.IgnoreTarget{{Pattern: "[.www3", Type: "CNAME"}} ) checkLengthsFull(t, existing, desired, 0, 1, 0, 0, false, nil, []*models.IgnoreTarget{{Pattern: "[.www3", Type: "CNAME"}})
} }
func TestInvalidTypeIgnoredTarget(t *testing.T) { func TestInvalidTypeIgnoredTarget(t *testing.T) {
@ -317,7 +317,7 @@ func TestInvalidTypeIgnoredTarget(t *testing.T) {
} }
}() }()
checkLengthsFull(t, existing, desired, 0, 1, 0, 0, false, nil, []*models.IgnoreTarget{{Pattern: "1.1.1.1", Type: "A"}} ) checkLengthsFull(t, existing, desired, 0, 1, 0, 0, false, nil, []*models.IgnoreTarget{{Pattern: "1.1.1.1", Type: "A"}})
} }
// from https://github.com/StackExchange/dnscontrol/issues/552 // from https://github.com/StackExchange/dnscontrol/issues/552

View File

@ -120,8 +120,8 @@ func require(call otto.FunctionCall) otto.Value {
func listFiles(call otto.FunctionCall) otto.Value { func listFiles(call otto.FunctionCall) otto.Value {
// Check amount of arguments provided // Check amount of arguments provided
if ! (len(call.ArgumentList) >= 1 && len(call.ArgumentList) <= 3) { if !(len(call.ArgumentList) >= 1 && len(call.ArgumentList) <= 3) {
throw(call.Otto, "glob requires at least one argument: folder (string). " + throw(call.Otto, "glob requires at least one argument: folder (string). "+
"Optional: recursive (bool) [true], fileExtension (string) [.js]") "Optional: recursive (bool) [true], fileExtension (string) [.js]")
} }
@ -143,8 +143,8 @@ func listFiles(call otto.FunctionCall) otto.Value {
} }
// Second: Recursive? // Second: Recursive?
var recursive bool = true; var recursive bool = true
if call.Argument(1).IsDefined() && ! call.Argument(1).IsNull() { if call.Argument(1).IsDefined() && !call.Argument(1).IsNull() {
if call.Argument(1).IsBoolean() { if call.Argument(1).IsBoolean() {
recursive, _ = call.Argument(1).ToBoolean() // If it should be recursive recursive, _ = call.Argument(1).ToBoolean() // If it should be recursive
} else { } else {
@ -153,11 +153,11 @@ func listFiles(call otto.FunctionCall) otto.Value {
} }
// Third: File extension filter. // Third: File extension filter.
var fileExtension string = ".js"; var fileExtension string = ".js"
if call.Argument(2).IsDefined() && ! call.Argument(2).IsNull() { if call.Argument(2).IsDefined() && !call.Argument(2).IsNull() {
if call.Argument(2).IsString() { if call.Argument(2).IsString() {
fileExtension = call.Argument(2).String() // Which file extension to filter for. fileExtension = call.Argument(2).String() // Which file extension to filter for.
if ! strings.HasPrefix(fileExtension, ".") { if !strings.HasPrefix(fileExtension, ".") {
// If it doesn't start with a dot, probably user forgot it and we do it instead. // If it doesn't start with a dot, probably user forgot it and we do it instead.
fileExtension = "." + fileExtension fileExtension = "." + fileExtension
} }
@ -176,7 +176,7 @@ func listFiles(call otto.FunctionCall) otto.Value {
// require() doesn't seem to handle well. For the sake of compatibility (and because slash looks nicer), // require() doesn't seem to handle well. For the sake of compatibility (and because slash looks nicer),
// we simply replace "\\" to "/" using filepath.ToSlash().. // we simply replace "\\" to "/" using filepath.ToSlash()..
path = filepath.ToSlash(filepath.Clean(path)) // convert to slashes for directories path = filepath.ToSlash(filepath.Clean(path)) // convert to slashes for directories
if ! recursive && fi.IsDir() { if !recursive && fi.IsDir() {
// If recursive is disabled, it is a dir what we're processing, and the path is different // If recursive is disabled, it is a dir what we're processing, and the path is different
// than specified, we're apparently in a different folder. Therefore: Skip it. // than specified, we're apparently in a different folder. Therefore: Skip it.
// So: Why this way? Because Walk() is always recursive and otherwise would require a complete // So: Why this way? Because Walk() is always recursive and otherwise would require a complete