Abort serve command if rootDir is inaccesible

This commit is contained in:
jola5
2017-01-28 22:29:49 +01:00
parent ab0d77f6f9
commit b948180b4e
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -6,6 +6,7 @@ import (
"github.com/smira/commander"
"github.com/smira/flag"
"net/http"
"golang.org/x/sys/unix"
)
func aptlyAPIServe(cmd *commander.Command, args []string) error {
@@ -18,6 +19,10 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error {
return commander.ErrCommandError
}
if unix.Access(context.Config().RootDir, unix.W_OK) != nil {
return fmt.Errorf("Configured rootDir '%s' inaccesible, check access rights", context.Config().RootDir)
}
listen := context.Flags().Lookup("listen").Value.String()
fmt.Printf("\nStarting web server at: %s (press Ctrl+C to quit)...\n", listen)