make mshell home directory during getremoteid

This commit is contained in:
sawka
2022-08-16 16:26:06 -07:00
parent 5a8ffa3544
commit 9542d14473
+15 -1
View File
@@ -198,7 +198,7 @@ func EnsureSessionDir(sessionId string) (string, error) {
if errors.Is(err, fs.ErrNotExist) {
err = os.MkdirAll(sdir, 0777)
if err != nil {
return "", err
return "", fmt.Errorf("cannot make mshell session directory[%s]: %w", sdir, err)
}
info, err = os.Stat(sdir)
}
@@ -254,6 +254,20 @@ func GoArchOptFile(goos string, goarch string) string {
func GetRemoteId() (string, error) {
mhome := GetMShellHomeDir()
homeInfo, err := os.Stat(mhome)
if errors.Is(err, fs.ErrNotExist) {
err = os.MkdirAll(mhome, 0777)
if err != nil {
return "", fmt.Errorf("cannot make mshell home directory[%s]: %w", mhome, err)
}
homeInfo, err = os.Stat(mhome)
}
if err != nil {
return "", fmt.Errorf("cannot stat mshell home directory[%s]: %w", mhome, err)
}
if !homeInfo.IsDir() {
return "", fmt.Errorf("mshell home directory[%s] is not a directory", mhome)
}
remoteIdFile := path.Join(mhome, RemoteIdFile)
fd, err := os.Open(remoteIdFile)
if errors.Is(err, fs.ErrNotExist) {