From b948180b4e951e41bac3a6673e670875bc310774 Mon Sep 17 00:00:00 2001 From: jola5 Date: Sat, 28 Jan 2017 22:29:49 +0100 Subject: [PATCH] Abort serve command if rootDir is inaccesible --- cmd/api_serve.go | 5 +++++ cmd/serve.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/cmd/api_serve.go b/cmd/api_serve.go index fd4c765b..6cd571bf 100644 --- a/cmd/api_serve.go +++ b/cmd/api_serve.go @@ -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) diff --git a/cmd/serve.go b/cmd/serve.go index d1c19e03..b053f244 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -12,6 +12,7 @@ import ( "os" "sort" "strings" + "golang.org/x/sys/unix" ) func aptlyServe(cmd *commander.Command, args []string) error { @@ -22,6 +23,10 @@ func aptlyServe(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) + } + if context.CollectionFactory().PublishedRepoCollection().Len() == 0 { fmt.Printf("No published repositories, unable to serve.\n") return nil