fix: make server path creation more robust
This commit is contained in:
parent
db5cbfa992
commit
48290aa316
@ -3,14 +3,12 @@ package server
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/server"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
@ -68,7 +66,10 @@ All communication between Abra and the server will use this SSH connection.
|
|||||||
domainName := "default"
|
domainName := "default"
|
||||||
|
|
||||||
if local {
|
if local {
|
||||||
os.Mkdir(path.Join(config.ABRA_DIR, "servers", domainName), 0755)
|
if err := server.CreateServerDir(domainName); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
logrus.Info("local server has been added")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,9 +126,12 @@ All communication between Abra and the server will use this SSH connection.
|
|||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("remote connection to '%s' is definitely up", domainName)
|
logrus.Debugf("remote connection to '%s' is definitely up", domainName)
|
||||||
logrus.Infof("server at '%s' has been added", domainName)
|
|
||||||
|
|
||||||
os.Mkdir(path.Join(config.ABRA_DIR, "servers", domainName), 0755)
|
if err := server.CreateServerDir(domainName); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("server at '%s' has been added", domainName)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
24
pkg/server/server.go
Normal file
24
pkg/server/server.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/pkg/config"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateServerDir creates a server directory under ~/.abra.
|
||||||
|
func CreateServerDir(serverName string) error {
|
||||||
|
serverPath := path.Join(config.ABRA_DIR, "servers", serverName)
|
||||||
|
|
||||||
|
if err := os.Mkdir(serverPath, 0755); err != nil {
|
||||||
|
if !os.IsExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("'%s' already exists, moving on...", serverPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user