"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "internal/util/helpers.go" between
AdGuardHome-0.105.1.tar.gz and AdGuardHome-0.105.2.tar.gz

About: AdGuard Home is a network-wide ads & trackers blocking DNS server. It operates as a DNS server that re-routes tracking domains to a "black hole," thus preventing your devices from connecting to those servers.

helpers.go  (AdGuardHome-0.105.1):helpers.go  (AdGuardHome-0.105.2)
// Package util contains various utilities. // Package util contains various utilities.
// //
// TODO(a.garipov): Such packages are widely considered an antipattern. Remove // TODO(a.garipov): Such packages are widely considered an antipattern. Remove
// this when we refactor our project structure. // this when we refactor our project structure.
package util package util
import ( import (
"bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
) )
// ContainsString checks if string is in the slice of strings. // ContainsString checks if string is in the slice of strings.
func ContainsString(strs []string, str string) bool { func ContainsString(strs []string, str string) bool {
for _, s := range strs { for _, s := range strs {
if s == str { if s == str {
return true return true
} }
skipping to change at line 67 skipping to change at line 69
} }
} }
*str = (*str)[k:] *str = (*str)[k:]
} else { } else {
s = *str s = *str
*str = "" *str = ""
} }
return strings.TrimSpace(s) return strings.TrimSpace(s)
} }
// IsOpenWRT checks if OS is OpenWRT. // IsOpenWRT returns true if host OS is OpenWRT.
func IsOpenWRT() bool { func IsOpenWRT() bool {
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
return false return false
} }
body, err := ioutil.ReadFile("/etc/os-release") const etcDir = "/etc"
// TODO(e.burkov): Take care of dealing with fs package after updating
// Go version to 1.16.
fileInfos, err := ioutil.ReadDir(etcDir)
if err != nil { if err != nil {
return false return false
} }
return strings.Contains(string(body), "OpenWrt") // fNameSubstr is a part of a name of the desired file.
const fNameSubstr = "release"
osNameData := []byte("OpenWrt")
for _, fileInfo := range fileInfos {
if fileInfo.IsDir() {
continue
}
if !strings.Contains(fileInfo.Name(), fNameSubstr) {
continue
}
body, err := ioutil.ReadFile(filepath.Join(etcDir, fileInfo.Name(
)))
if err != nil {
continue
}
if bytes.Contains(body, osNameData) {
return true
}
}
return false
} }
 End of changes. 5 change blocks. 
3 lines changed or deleted 33 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)