forked from toolshed/abra
		
	fix: make server path creation more robust
This commit is contained in:
		| @ -3,14 +3,12 @@ package server | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"os" | ||||
| 	"os/user" | ||||
| 	"path" | ||||
| 	"strings" | ||||
|  | ||||
| 	"coopcloud.tech/abra/cli/internal" | ||||
| 	"coopcloud.tech/abra/pkg/client" | ||||
| 	"coopcloud.tech/abra/pkg/config" | ||||
| 	"coopcloud.tech/abra/pkg/server" | ||||
| 	"github.com/sirupsen/logrus" | ||||
| 	"github.com/urfave/cli/v2" | ||||
| ) | ||||
| @ -68,7 +66,10 @@ All communication between Abra and the server will use this SSH connection. | ||||
| 		domainName := "default" | ||||
|  | ||||
| 		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 | ||||
| 		} | ||||
|  | ||||
| @ -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.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 | ||||
| 	}, | ||||
|  | ||||
							
								
								
									
										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 | ||||
| } | ||||
		Reference in New Issue
	
	Block a user