From ea3572135b0a6148a8f9a4af115adf90d97ba610 Mon Sep 17 00:00:00 2001 From: Yash-Handa Date: Tue, 29 Sep 2020 11:30:48 +0530 Subject: [PATCH] Added some code refactoring --- .github/githooks/pre-push | 43 --------------------------------- internal/api/api.go | 2 +- internal/dir/dir.go | 17 +++---------- internal/dir/formatterStuff.go | 7 ++++++ logo-ls.1.gz | Bin 1614 -> 1613 bytes 5 files changed, 12 insertions(+), 57 deletions(-) delete mode 100755 .github/githooks/pre-push diff --git a/.github/githooks/pre-push b/.github/githooks/pre-push deleted file mode 100755 index e56cd33..0000000 --- a/.github/githooks/pre-push +++ /dev/null @@ -1,43 +0,0 @@ -# #!/bin/sh - -# R_NAME=$1 -# R_URL=$2 - -# error_exit() -# { -# if [ "$?" != "0" ]; then -# nl=$'\n' -# echo "$1""$nl""$2""$nl""$nl""Aborting push to ""$R_NAME"" (""$R_URL"")" 1>&2 -# exit 1 -# fi -# } - -# # Build binary for variety of arch -# # linux amd64 -# ERROR=$(go env -w GOOS=linux GOARCH=amd64 2>&1 > /dev/null) -# error_exit "Cannot set GOOS=linux and GOARCH=amd64:" "$ERROR" -# ERROR=$(go build -o build/logo-ls-linux-amd64 2>&1 > /dev/null) -# error_exit "Cannot build logo-ls-linux-amd64:" "$ERROR" - -# # linux arm64 -# ERROR=$(go env -w GOOS=linux GOARCH=arm64 2>&1 > /dev/null) -# error_exit "Cannot set GOOS=linux and GOARCH=arm64:" "$ERROR" -# ERROR=$(go build -o build/logo-ls-linux-arm64 2>&1 > /dev/null) -# error_exit "Cannot build logo-ls-linux-arm64:" "$ERROR" - -# # linux 386 -# ERROR=$(go env -w GOOS=linux GOARCH=386 2>&1 > /dev/null) -# error_exit "Cannot set GOOS=linux and GOARCH=386:" "$ERROR" -# ERROR=$(go build -o build/logo-ls-linux-386 2>&1 > /dev/null) -# error_exit "Cannot build logo-ls-linux-386:" "$ERROR" - -# # darwin amd64 -# ERROR=$(go env -w GOOS=darwin GOARCH=amd64 2>&1 > /dev/null) -# error_exit "Cannot set GOOS=darwin and GOARCH=amd64:" "$ERROR" -# ERROR=$(go build -o build/logo-ls-darwin-amd64 2>&1 > /dev/null) -# error_exit "Cannot build logo-ls-darwin-amd64:" "$ERROR" - -# # reset env to default -# go env -u GOOS GOARCH - -# exit 0 diff --git a/internal/api/api.go b/internal/api/api.go index c9c0682..bd83f1a 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -253,7 +253,7 @@ func Bootstrap() { // if f_V is provided version will be printed and exit(0) if *f_V { - fmt.Printf("logo-ls %s\nCopyright (c) 2020 Yash Handa\nLicense MIT .\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n", "v1.3.5") + fmt.Printf("logo-ls %s\nCopyright (c) 2020 Yash Handa\nLicense MIT .\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n", "v1.3.6") fmt.Println("\nWritten by Yash Handa") os.Exit(sysState.GetExitCode()) } diff --git a/internal/dir/dir.go b/internal/dir/dir.go index 95c3f50..79c22e3 100644 --- a/internal/dir/dir.go +++ b/internal/dir/dir.go @@ -10,7 +10,6 @@ import ( "path/filepath" "sort" "strings" - "syscall" "time" "github.com/Yash-Handa/logo-ls/assets" @@ -78,9 +77,7 @@ func New(d *os.File) (*dir, error) { t.info.owner, t.info.group = getOwnerGroupInfo(ds) } if api.FlagVector&api.Flag_s > 0 { - if s, ok := ds.Sys().(*syscall.Stat_t); ok { - t.info.blocks = s.Blocks - } + t.info.blocks = getFileBlocks(ds) } if api.FlagVector&api.Flag_i == 0 { t.info.icon = assets.Icon_Def["diropen"].GetGlyph() @@ -115,9 +112,7 @@ func New(d *os.File) (*dir, error) { f.owner, f.group = getOwnerGroupInfo(v) } if api.FlagVector&api.Flag_s > 0 { - if s, ok := v.Sys().(*syscall.Stat_t); ok { - f.blocks = s.Blocks - } + f.blocks = getFileBlocks(v) } if api.FlagVector&api.Flag_i == 0 { @@ -165,9 +160,7 @@ func New(d *os.File) (*dir, error) { t.parent.owner, t.parent.group = getOwnerGroupInfo(pds) } if api.FlagVector&api.Flag_s > 0 { - if s, ok := pds.Sys().(*syscall.Stat_t); ok { - t.parent.blocks = s.Blocks - } + t.parent.blocks = getFileBlocks(pds) } if api.FlagVector&api.Flag_i == 0 { t.parent.icon = assets.Icon_Def["diropen"].GetGlyph() @@ -202,9 +195,7 @@ func New_ArgFiles(files []os.FileInfo) *dir { f.owner, f.group = getOwnerGroupInfo(v) } if api.FlagVector&api.Flag_s > 0 { - if s, ok := v.Sys().(*syscall.Stat_t); ok { - f.blocks = s.Blocks - } + f.blocks = getFileBlocks(v) } if api.FlagVector&api.Flag_i == 0 { f.icon, f.iconColor = getIcon(f.name, f.ext, f.indicator) diff --git a/internal/dir/formatterStuff.go b/internal/dir/formatterStuff.go index f52d971..7c569f5 100644 --- a/internal/dir/formatterStuff.go +++ b/internal/dir/formatterStuff.go @@ -115,6 +115,13 @@ func getOwnerGroupInfo(fi os.FileInfo) (o string, g string) { return } +func getFileBlocks(fi os.FileInfo) int64 { + if s, ok := fi.Sys().(*syscall.Stat_t); ok { + return s.Blocks + } + return 0 +} + // get indicator of the file func getIndicator(modebit os.FileMode) (i string) { switch { diff --git a/logo-ls.1.gz b/logo-ls.1.gz index 6e36120d86a0f2f00e94c4063abc13c470f4ba41..94e59c96b5ea8afeb84c790fe8f6e7fb16613ff6 100644 GIT binary patch delta 1604 zcmV-K2D|yr49yG&ABzYGRLydc2OfX*?b5s45Fms$UexlEHO((a>YpVjUPcV2;>2V*aQk=GmEK0t6c^x<}R-~SC@Xkf=Qta-u}Gkgh) zJw!ZCTN{=@(|z^UZMI#<4esFH8+f&QA1ciXRD7NqzFBYutwyVX3$a|wTC9Iz+jQIR z8(f%a-0aE?;w*K=as4|OcSe2ZXgIF{Ze=Wnl&v|eq=It{>*7C*y@@~c9rxzA?R=ZB zhVyEz`8Vr?%iekriC9jRugz@x>C3!6Urit3U=zTW#Th?aT#1j@@tKo)Z&O@}iI+M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