goint there
This commit is contained in:
1 parent
776c73b91c
commit
c94a2042f1
7 files changed
+292
-36
No files matched your search
@@ -0,0 +1,9 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
const DIRECTORY_PERMISSION os.FileMode = 0700
|
||||
const PUBLIC_KEY_PERMISSION os.FileMode = 0644
|
||||
const PRIVATE_KEY_PERMISSION os.FileMode = 0600
|
||||
@@ -0,0 +1,39 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
var ecryptoDir string
|
||||
|
||||
func ensureEcryptoDirectoryIsOkay(dir string) error {
|
||||
stat, err := os.Stat(dir)
|
||||
if os.IsNotExist(err) {
|
||||
return os.Mkdir(dir, DIRECTORY_PERMISSION)
|
||||
} else if err != nil {
|
||||
return err
|
||||
} else if !stat.IsDir() {
|
||||
return errors.New(dir + " is not a directory")
|
||||
} else if perm := stat.Mode().Perm(); perm != DIRECTORY_PERMISSION {
|
||||
msg := fmt.Sprintf("root folder has bad file permission. should be set to %v but vas %v", DIRECTORY_PERMISSION, perm)
|
||||
return errors.New(msg)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
ecryptoDir = path.Join(os.Getenv("HOME"), ".ecrypto")
|
||||
if err := ensureEcryptoDirectoryIsOkay(ecryptoDir); err != nil {
|
||||
fmt.Println("cannot work with eCrypto directory", err)
|
||||
os.Exit(1)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func GetEcryptoDir() string {
|
||||
return ecryptoDir
|
||||
}
|
||||
Reference in new issue
Block a user