From 325976dd3d19156429708f0ce66697042bc5df26 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Sun, 1 Sep 2019 20:09:55 +0200 Subject: [PATCH 01/18] added spinner library --- cmd/pighosts/main.go | 2 +- go.mod | 2 ++ go.sum | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/pighosts/main.go b/cmd/pighosts/main.go index 2d5095f..3ecb888 100644 --- a/cmd/pighosts/main.go +++ b/cmd/pighosts/main.go @@ -101,7 +101,7 @@ Command: func ChkErr(err error) { if err != nil { logrus.Error(err, "\n\n") - logrus.Errorf("Version : %v, commit %v, built at %v", version, commit, date) + logrus.Errorf("Version : %v - Commit: %v - Built: %v", version, commit, date) logrus.Errorf("Stack : %s", string(debug.Stack())) os.Exit(1) } diff --git a/go.mod b/go.mod index a41d51d..223dfaa 100644 --- a/go.mod +++ b/go.mod @@ -5,3 +5,5 @@ go 1.12 require github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 require github.com/sirupsen/logrus v1.4.2 + +require github.com/briandowns/spinner v1.6.1 // indirect diff --git a/go.sum b/go.sum index 8b397cc..60945ee 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,13 @@ +github.com/briandowns/spinner v1.6.1/go.mod h1://Zf9tMcxfRUA36V23M6YGEAv+kECGfvpnLTnb8n4XQ= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= @@ -11,5 +15,6 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= From efa8900f1ec96714e391824421eeca83ff14f026 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Sun, 1 Sep 2019 20:29:48 +0200 Subject: [PATCH 02/18] added spinner --- cmd/pighosts/main.go | 10 ++++++++++ go.mod | 2 +- go.sum | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/pighosts/main.go b/cmd/pighosts/main.go index 3ecb888..bb59f39 100644 --- a/cmd/pighosts/main.go +++ b/cmd/pighosts/main.go @@ -5,7 +5,9 @@ import ( "os" pighosts "pigHosts" "runtime/debug" + "time" + "github.com/briandowns/spinner" "github.com/docopt/docopt-go" "github.com/sirupsen/logrus" ) @@ -45,12 +47,18 @@ Command: load load custom hosts from external urls declared in the file: '.pigHosts/pigHosts.urls' force_init delete and create a new set of configuration files: '.pigHosts/pigHosts.excluded' and '.pigHosts/pigHosts.urls' in your user/home folder` + ind := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner + ind.Start() + time.Sleep(2 * time.Second) + ind.Stop() + arguments, err := docopt.ParseDoc(usage) ChkErr(err) r, err := arguments.Bool("--help") ChkErr(err) if r { + docopt.PrintHelpAndExit(err, usage) os.Exit(0) } @@ -83,10 +91,12 @@ Command: r, err = arguments.Bool("load") ChkErr(err) if r { + logrus.Info("Start process...") err = pighosts.LoadHostsFile() ChkErr(err) logrus.Info("End process.") + os.Exit(0) } docopt.PrintHelpAndExit(err, usage) diff --git a/go.mod b/go.mod index 223dfaa..1564b35 100644 --- a/go.mod +++ b/go.mod @@ -6,4 +6,4 @@ require github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 require github.com/sirupsen/logrus v1.4.2 -require github.com/briandowns/spinner v1.6.1 // indirect +require github.com/briandowns/spinner v1.6.1 diff --git a/go.sum b/go.sum index 60945ee..532e422 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,16 @@ +github.com/briandowns/spinner v1.6.1 h1:LBxHu5WLyVuVEtTD72xegiC7QJGx598LBpo3ywKTapA= github.com/briandowns/spinner v1.6.1/go.mod h1://Zf9tMcxfRUA36V23M6YGEAv+kECGfvpnLTnb8n4XQ= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= From 46d3a3140d5fdb027bcb0670ab3cec14235cc893 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Mon, 2 Sep 2019 09:59:01 +0200 Subject: [PATCH 03/18] added process animations --- cmd/pighosts/main.go | 7 ------- resource.go | 9 +++++++-- utilsHostFile.go | 13 ++++++++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmd/pighosts/main.go b/cmd/pighosts/main.go index bb59f39..ab60a7b 100644 --- a/cmd/pighosts/main.go +++ b/cmd/pighosts/main.go @@ -5,9 +5,7 @@ import ( "os" pighosts "pigHosts" "runtime/debug" - "time" - "github.com/briandowns/spinner" "github.com/docopt/docopt-go" "github.com/sirupsen/logrus" ) @@ -47,11 +45,6 @@ Command: load load custom hosts from external urls declared in the file: '.pigHosts/pigHosts.urls' force_init delete and create a new set of configuration files: '.pigHosts/pigHosts.excluded' and '.pigHosts/pigHosts.urls' in your user/home folder` - ind := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner - ind.Start() - time.Sleep(2 * time.Second) - ind.Stop() - arguments, err := docopt.ParseDoc(usage) ChkErr(err) diff --git a/resource.go b/resource.go index 130b67e..c8ba341 100644 --- a/resource.go +++ b/resource.go @@ -1,8 +1,13 @@ package pighosts -import "time" -import "os" +import ( + "os" + "time" + "github.com/briandowns/spinner" +) + +var spinnerInd = spinner.New(spinner.CharSets[9], 100*time.Millisecond) var pigHostsUrls = "" var pigHostsExcluded = "" diff --git a/utilsHostFile.go b/utilsHostFile.go index 52394f4..21b16ad 100644 --- a/utilsHostFile.go +++ b/utilsHostFile.go @@ -15,6 +15,7 @@ import ( func UnloadHostsFile() error { + spinnerInd.Restart() //prepare a new empty version of host file err := prepareHostFile(nil) if err != nil { @@ -29,6 +30,7 @@ func UnloadHostsFile() error { if err != nil { return err } + spinnerInd.Stop() return nil } @@ -38,12 +40,14 @@ func LoadHostsFile() error { logrus.Info("Download hosts list:") hosts := make([]string, 0) for _, k := range defaultHostsUrlsTmp { + logrus.Info("\t", k) + spinnerInd.Restart() z, err := downlaodRemoteList(k) if err != nil { return err } hosts = append(hosts, z...) - logrus.Info("\t", k, " -- Num. hosts download: ", len(z)) + spinnerInd.Stop() } a := prepareHostsList(hosts) @@ -67,6 +71,7 @@ func LoadHostsFile() error { } func downlaodRemoteList(url string) ([]string, error) { + if url == "" || (!strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://")) { return []string{}, nil } @@ -92,10 +97,12 @@ func downlaodRemoteList(url string) ([]string, error) { } r := strings.FieldsFunc(strings.ReplaceAll(string(b), "\r\n", "\n"), f) + return r, nil } func prepareHostFile(hosts []string) error { + header := "\n\n" + headerHostFile footer := "\n\n" + footerHostFile + "\n\n" @@ -151,6 +158,7 @@ func prepareHostFile(hosts []string) error { } func readHostFile() (string, error) { + result := "" f, err := os.OpenFile(hostFile, os.O_RDONLY, os.ModeType) if err != nil { @@ -180,10 +188,12 @@ func readHostFile() (string, error) { b := make([]byte, startLine) f.ReadAt(b, 0) result = string(b) + return result, nil } func backupHostFile(s string) (int64, error) { + dir := path.Dir(hostFileBak) if _, err := os.Stat(dir); os.IsNotExist(err) { err = nil @@ -204,5 +214,6 @@ func backupHostFile(s string) (int64, error) { if err != nil { return 0, err } + return stat.Size(), nil } From d01d6883c66a6ae100c5f7cea41bfeb1e33e5b08 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Mon, 2 Sep 2019 10:00:05 +0200 Subject: [PATCH 04/18] typo --- resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/resource.go b/resource.go index c8ba341..1a8aa89 100644 --- a/resource.go +++ b/resource.go @@ -12,7 +12,6 @@ var pigHostsUrls = "" var pigHostsExcluded = "" const numHostPerLine = 9 - const nonRoutable = "0.0.0.0" const localHostIP4 = "127.0.0.1" const localHostIP6 = "::1" From 6d610bbba9e92c2d917564cc9b815ae6cd7c0852 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Mon, 2 Sep 2019 19:25:54 +0200 Subject: [PATCH 05/18] add linux support --- resource.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/resource.go b/resource.go index 1a8aa89..ab29e51 100644 --- a/resource.go +++ b/resource.go @@ -2,6 +2,7 @@ package pighosts import ( "os" + "runtime" "time" "github.com/briandowns/spinner" @@ -11,10 +12,13 @@ var spinnerInd = spinner.New(spinner.CharSets[9], 100*time.Millisecond) var pigHostsUrls = "" var pigHostsExcluded = "" -const numHostPerLine = 9 const nonRoutable = "0.0.0.0" const localHostIP4 = "127.0.0.1" const localHostIP6 = "::1" +const hostFileWin = "/Windows/System32/drivers/etc/hosts" +const hostFileLinux = "TBD" +const numHostPerLineWin = 9 +const numHostPerLineLinux = 1 var filterSpecificHostDefault = []string{ "127.0.0.1 localhost", @@ -62,8 +66,8 @@ var filterSpecificHostTmp = []string{} const headerHostFile = "###--pigHost_START------------------------------------" const footerHostFile = "###--pigHosts_END-------------------------------------" -const hostFile = "/Windows/System32/drivers/etc/hosts" - +var hostFile = hostFileWin +var numHostPerLine = numHostPerLineWin var hostFileNew = os.TempDir() + "/pigHostBak/host.new" var hostFileEmpty = os.TempDir() + "/pigHostBak/host.empty" var hostFileBak = os.TempDir() + "/pigHostBak/host_" + time.Now().Format("20060201T1504") + ".bak" @@ -84,3 +88,10 @@ const manifest = ` ` + +func init() { + if runtime.GOOS != "windows" { + hostFile = hostFileLinux + numHostPerLine = numHostPerLineLinux + } +} From ce34a714c8341207ca511de204ad18a74d6e87a4 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Mon, 2 Sep 2019 19:45:12 +0200 Subject: [PATCH 06/18] modfied exe --- Taskfile.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index f04118c..3bc42f6 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -19,11 +19,11 @@ tasks: desc: Download modules and force a build of project using vendor folder. deps: [mod-vendor] cmds: - - go build -mod vendor -i -a -o $GOPATH/bin/pigHosts.exe ./cmd/... + - go build -mod vendor -i -a -o $GOPATH/bin/pigHosts{{exeExt}} ./cmd/... build: desc: Build project using vendor folder. cmds: - - go build -mod vendor -i -o $GOPATH/bin/pigHosts.exe ./cmd/... + - go build -mod vendor -i -o $GOPATH/bin/pigHosts{{exeExt}} ./cmd/... mod-vendor: desc: Download module into vendor folder. cmds: From d8c2a970060fc4bdb948108069eb424f8e7350db Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Mon, 2 Sep 2019 20:26:07 +0200 Subject: [PATCH 07/18] fix creation directory --- utilsConfig.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilsConfig.go b/utilsConfig.go index e8379ac..8c8dcde 100644 --- a/utilsConfig.go +++ b/utilsConfig.go @@ -46,7 +46,7 @@ func InitPigHosts(force bool) error { if _, err := os.Stat(homeFolder); os.IsNotExist(err) { err = nil - err = os.Mkdir(homeFolder, os.ModeDir) + err = os.Mkdir(homeFolder, os.ModePerm) if err != nil { return err } From ea0e3ddeaf1fef4cd3e6bc1aac204b57bfdb4f97 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Mon, 2 Sep 2019 20:26:18 +0200 Subject: [PATCH 08/18] added hosts linux path --- resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource.go b/resource.go index ab29e51..839ac02 100644 --- a/resource.go +++ b/resource.go @@ -16,7 +16,7 @@ const nonRoutable = "0.0.0.0" const localHostIP4 = "127.0.0.1" const localHostIP6 = "::1" const hostFileWin = "/Windows/System32/drivers/etc/hosts" -const hostFileLinux = "TBD" +const hostFileLinux = "/etc/hosts" const numHostPerLineWin = 9 const numHostPerLineLinux = 1 From 9972059a59911b07086e80f7a053adc2c2481f82 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:06:51 +0200 Subject: [PATCH 09/18] typo --- cmd/pighosts/main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/pighosts/main.go b/cmd/pighosts/main.go index ab60a7b..be82fe5 100644 --- a/cmd/pighosts/main.go +++ b/cmd/pighosts/main.go @@ -26,7 +26,11 @@ func init() { } func main() { - usage := `pigHost + homeFolder, err := os.UserHomeDir() + ChkErr(err) + + usage := ` +pigHost Usage: pigHost [load | unload | force_init] [-h | -v | -o] pigHost (load) @@ -41,9 +45,10 @@ Options: -v, --version view version Command: + load load custom hosts from external urls declared in the file: '` + homeFolder + `/.pigHosts/pigHosts.urls' unload disable and remove custom hosts - load load custom hosts from external urls declared in the file: '.pigHosts/pigHosts.urls' - force_init delete and create a new set of configuration files: '.pigHosts/pigHosts.excluded' and '.pigHosts/pigHosts.urls' in your user/home folder` + force_init delete and create a new set of configuration files: '` + homeFolder + `/.pigHosts/pigHosts.excluded' and '` + homeFolder + `/.pigHosts/pigHosts.urls' + ` arguments, err := docopt.ParseDoc(usage) ChkErr(err) From e07c7ce6b132e76292f6de91ec8d85fbafbff67e Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:09:53 +0200 Subject: [PATCH 10/18] update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e5284dd..3286380 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Options: -v, --version view version Command: + load load custom hosts from external urls declared in the file: '/.pigHosts/pigHosts.urls' unload disable and remove custom hosts - load load custom hosts from external urls declared in the file: '.pigHosts/pigHosts.urls' - force_init delete and create a new set of configuration files: '.pigHosts/pigHosts.excluded' and '.pigHosts/pigHosts.urls' in your user/home folder + force_init delete and create a new set of configuration files: '/.pigHosts/pigHosts.excluded' and '/.pigHosts/pigHosts.urls' ``` From 46f43c92026b4096daf6d66f9da29877b249999d Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:11:11 +0200 Subject: [PATCH 11/18] typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3286380..a446d7e 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Options: -v, --version view version Command: - load load custom hosts from external urls declared in the file: '/.pigHosts/pigHosts.urls' + load load custom hosts from external urls declared in the file: '/.pigHosts/pigHosts.urls' unload disable and remove custom hosts - force_init delete and create a new set of configuration files: '/.pigHosts/pigHosts.excluded' and '/.pigHosts/pigHosts.urls' + force_init delete and create a new set of configuration files: '/.pigHosts/pigHosts.excluded' and '/.pigHosts/pigHosts.urls' ``` From b6c1dba456f9470cfe656f06d252d0c519d284fa Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:11:37 +0200 Subject: [PATCH 12/18] update docs --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index a446d7e..3ed2ea5 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@ - Possibility to customize your download blacklist links. - Possibility to esclude specific hosts. - On Windows: optimized load hosts, more hosts per line. -- Only for Windows. -- *Linux version is wip...* +- Windows & Linux version. ### Use: From 0b28c3e04ddbd6e4ca52fb965088370c20a8465f Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:14:50 +0200 Subject: [PATCH 13/18] typo --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index d5ba1d8..3ed2ea5 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,3 @@ Tools and libraries: - https://github.com/sirupsen/logrus - https://github.com/go-task/task - https://github.com/goreleaser/goreleaser -... \ No newline at end of file From 0546b1a1ee09b5c8797d00f7abe7d6d4bc4e088b Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:15:26 +0200 Subject: [PATCH 14/18] typo --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 3ed2ea5..ea96e2f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ - Add and remove blacklist hosts, from your hosts file. - Possibility to customize your download blacklist links. - Possibility to esclude specific hosts. -- On Windows: optimized load hosts, more hosts per line. - Windows & Linux version. ### Use: From 7bba50f5a78695b065a4ac40ea496c40082c2fc2 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:20:53 +0200 Subject: [PATCH 15/18] typo --- utilsHostFile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilsHostFile.go b/utilsHostFile.go index 21b16ad..b63b04b 100644 --- a/utilsHostFile.go +++ b/utilsHostFile.go @@ -65,7 +65,7 @@ func LoadHostsFile() error { if err != nil { return err } - logrus.Info("Host file updated.") + logrus.Info("Hosts file updated.") return nil } From 9fffc4bf6867f00a4b65a35b7450666e4c79ab33 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:46:23 +0200 Subject: [PATCH 16/18] fix: creation folder --- utilsHostFile.go | 4 ++-- utilsHostString_test.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/utilsHostFile.go b/utilsHostFile.go index b63b04b..80a0016 100644 --- a/utilsHostFile.go +++ b/utilsHostFile.go @@ -109,7 +109,7 @@ func prepareHostFile(hosts []string) error { dir := path.Dir(hostFileNew) if _, err := os.Stat(dir); os.IsNotExist(err) { err = nil - err = os.Mkdir(dir, os.ModeDir) + err = os.Mkdir(dir, os.ModePerm) if err != nil { return err } @@ -197,7 +197,7 @@ func backupHostFile(s string) (int64, error) { dir := path.Dir(hostFileBak) if _, err := os.Stat(dir); os.IsNotExist(err) { err = nil - err = os.Mkdir(dir, os.ModeDir) + err = os.Mkdir(dir, os.ModePerm) if err != nil { return 0, err } diff --git a/utilsHostString_test.go b/utilsHostString_test.go index 221ced8..ac0b5fb 100644 --- a/utilsHostString_test.go +++ b/utilsHostString_test.go @@ -2,6 +2,7 @@ package pighosts import ( "reflect" + "runtime" "strings" "testing" ) @@ -107,6 +108,10 @@ func Test_splitHostPerLine(t *testing.T) { type args struct { hosts map[string]int } + result := []int{10, 7} + if runtime.GOOS != "windows" { + result = []int{2, 2} + } tests := []struct { name string args args @@ -130,7 +135,7 @@ func Test_splitHostPerLine(t *testing.T) { "1phads7.com": 2, "test.test.io": 1}, }, - []int{10, 7}, + result, }, } for _, tt := range tests { From cedc96485b39480beba6bedd40638a26fa6eae2b Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 08:57:52 +0200 Subject: [PATCH 17/18] updated help online --- cmd/pighosts/main.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmd/pighosts/main.go b/cmd/pighosts/main.go index be82fe5..d1cc2d6 100644 --- a/cmd/pighosts/main.go +++ b/cmd/pighosts/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "os" pighosts "pigHosts" "runtime/debug" @@ -56,7 +55,6 @@ Command: r, err := arguments.Bool("--help") ChkErr(err) if r { - docopt.PrintHelpAndExit(err, usage) os.Exit(0) } @@ -97,11 +95,8 @@ Command: os.Exit(0) } - docopt.PrintHelpAndExit(err, usage) - - err = fmt.Errorf("My Err: %v", "super error!") - ChkErr(err) + logrus.Info("Try to use: -h or --help for help online.\n") os.Exit(0) } From 5f815aed3bce21230ceff6932d9346d6ab6d2fc9 Mon Sep 17 00:00:00 2001 From: "pietro.partescano" Date: Tue, 3 Sep 2019 09:02:24 +0200 Subject: [PATCH 18/18] typo --- cmd/pighosts/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/pighosts/main.go b/cmd/pighosts/main.go index d1cc2d6..f6fb61c 100644 --- a/cmd/pighosts/main.go +++ b/cmd/pighosts/main.go @@ -96,7 +96,7 @@ Command: os.Exit(0) } - logrus.Info("Try to use: -h or --help for help online.\n") + logrus.Info("Try to use: option -h or --help for help online.\n") os.Exit(0) }