Fixed reading terminal input on Windows, fixed upload error for Files > 20MB, fixed build tags

This commit is contained in:
Marc Ole Bulling
2021-05-11 14:22:09 +02:00
parent 8f02aeb881
commit 84c6a07635
7 changed files with 26 additions and 18 deletions

View File

@@ -13,4 +13,5 @@ jobs:
with:
go-version: '^1.16.4'
- run: go test ./... --tags=test,awsmock
- run: go clean -testcache
- run: go test ./... --tags=test,noaws

View File

@@ -12,8 +12,9 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
"os"
"runtime"
"strconv"
"strings"
"sync"
@@ -233,21 +234,29 @@ func askForPassword() string {
}
return envPassword
}
password1, err := terminal.ReadPassword(0)
helper.Check(err)
if utf8.RuneCountInString(string(password1)) < minLengthPassword {
password1 := readPassword()
if utf8.RuneCountInString(password1) < minLengthPassword {
fmt.Println("\nPassword needs to be at least " + strconv.Itoa(minLengthPassword) + " characters long")
return askForPassword()
}
fmt.Print("\nPassword (repeat): ")
password2, err := terminal.ReadPassword(0)
helper.Check(err)
if string(password1) != string(password2) {
password2 := readPassword()
if password1 != password2 {
fmt.Println("\nPasswords dont match")
return askForPassword()
}
fmt.Println()
return string(password1)
return password1
}
func readPassword() string {
if runtime.GOOS != "windows" {
pw, err := term.ReadPassword(0)
if err == nil {
return string(pw)
}
}
return helper.ReadLine()
}
// Asks if the server shall be bound to 127.0.0.1 or loads it from env and returns result as bool

View File

@@ -7,7 +7,6 @@ Simplified OS functions
import (
"bufio"
"os"
"strings"
)
// FolderExists returns true if a folder exists
@@ -38,9 +37,10 @@ func CreateDir(name string) {
// ReadLine reads a line from the terminal and returns it as a string
func ReadLine() string {
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
return strings.Replace(text, "\n", "", -1)
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
text := scanner.Text()
return text
}
// Check panics if error is not nil

View File

@@ -75,6 +75,7 @@ func deleteTempFile(file *os.File) {
if file == nil {
return
}
file.Close()
err := os.Remove(file.Name())
helper.Check(err)
}

View File

@@ -1,5 +1,4 @@
// +build !noaws
// +build !awsmock
// +build !noaws,!awsmock
package aws

View File

@@ -1,5 +1,4 @@
// +build !noaws
// +build awsmock
// +build !noaws,awsmock
package aws

View File

@@ -1,5 +1,4 @@
// +build noaws
// +build !awsmock
// +build noaws,!awsmock
package aws