mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 23:16:53 +00:00
Fix Docker os.Rename invalid cross-device link issue (#386)
* Adds new file.Move func to address a bug with Golang/Docker volumes when using os.Rename Also uses TempDir for tests instead of live directories and increases test coverage for file.Write * Goimport the imports * Make usage of file package name consistent so it no longer clashes with vars * Remove outputFile if io.Copy fails
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/file"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
)
|
||||
|
||||
@@ -43,19 +43,19 @@ func main() {
|
||||
key = string(result)
|
||||
}
|
||||
|
||||
file, err := ioutil.ReadFile(inFile)
|
||||
fileData, err := ioutil.ReadFile(inFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to read input file %s. Error: %s.", inFile, err)
|
||||
}
|
||||
|
||||
if config.ConfirmECS(file) && encrypt {
|
||||
if config.ConfirmECS(fileData) && encrypt {
|
||||
log.Println("File is already encrypted. Decrypting..")
|
||||
encrypt = false
|
||||
}
|
||||
|
||||
if !config.ConfirmECS(file) && !encrypt {
|
||||
if !config.ConfirmECS(fileData) && !encrypt {
|
||||
var result interface{}
|
||||
errf := config.ConfirmConfigJSON(file, result)
|
||||
errf := config.ConfirmConfigJSON(fileData, result)
|
||||
if errf != nil {
|
||||
log.Fatal("File isn't in JSON format")
|
||||
}
|
||||
@@ -65,18 +65,18 @@ func main() {
|
||||
|
||||
var data []byte
|
||||
if encrypt {
|
||||
data, err = config.EncryptConfigFile(file, []byte(key))
|
||||
data, err = config.EncryptConfigFile(fileData, []byte(key))
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to encrypt config data. Error: %s.", err)
|
||||
}
|
||||
} else {
|
||||
data, err = config.DecryptConfigFile(file, []byte(key))
|
||||
data, err = config.DecryptConfigFile(fileData, []byte(key))
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to decrypt config data. Error: %s.", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = common.WriteFile(outFile, data)
|
||||
err = file.Write(outFile, data)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to write output file %s. Error: %s", outFile, err)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/file"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/engine"
|
||||
@@ -754,7 +755,7 @@ func saveConfig(config *Config) {
|
||||
}
|
||||
|
||||
log.Printf("Outputting to: %v", filepath.Join(dir, "wrapperconfig.json"))
|
||||
err = common.WriteFile(filepath.Join(dir, "wrapperconfig.json"), jsonOutput)
|
||||
err = file.Write(filepath.Join(dir, "wrapperconfig.json"), jsonOutput)
|
||||
if err != nil {
|
||||
log.Printf("Encountered error writing to disk: %v", err)
|
||||
return
|
||||
@@ -775,7 +776,7 @@ func outputToJSON(exchangeResponses []ExchangeResponses) {
|
||||
}
|
||||
|
||||
log.Printf("Outputting to: %v", filepath.Join(dir, fmt.Sprintf("%v.json", outputFileName)))
|
||||
err = common.WriteFile(filepath.Join(dir, fmt.Sprintf("%v.json", outputFileName)), jsonOutput)
|
||||
err = file.Write(filepath.Join(dir, fmt.Sprintf("%v.json", outputFileName)), jsonOutput)
|
||||
if err != nil {
|
||||
log.Printf("Encountered error writing to disk: %v", err)
|
||||
return
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/file"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -83,13 +83,13 @@ func main() {
|
||||
log.Fatalf("key pem data is nil")
|
||||
}
|
||||
|
||||
err = common.WriteFile("key.pem", keyData)
|
||||
err = file.Write("key.pem", keyData)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to write key.pem file %s", err)
|
||||
}
|
||||
log.Printf("wrote key.pem file")
|
||||
|
||||
err = common.WriteFile("cert.pem", certData)
|
||||
err = file.Write("cert.pem", certData)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to write cert.pem file %s", err)
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func main() {
|
||||
}
|
||||
|
||||
path := filepath.Join(outputFolder, "sqlboiler.json")
|
||||
err = ioutil.WriteFile(path, jsonOutput, 0644)
|
||||
err = ioutil.WriteFile(path, jsonOutput, 0770)
|
||||
if err != nil {
|
||||
fmt.Printf("Write failed: %v", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/file"
|
||||
)
|
||||
|
||||
func encodePEM(privKey *ecdsa.PrivateKey, pubKey bool) ([]byte, error) {
|
||||
@@ -54,8 +54,8 @@ func decodePEM(pemPrivKey []byte) (*ecdsa.PrivateKey, error) {
|
||||
return x509.ParseECPrivateKey(x509Enc)
|
||||
}
|
||||
|
||||
func writeFile(file string, data []byte) error {
|
||||
return common.WriteFile(file, data)
|
||||
func writeFile(fileName string, data []byte) error {
|
||||
return file.Write(fileName, data)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user