This commit is contained in:
jola5
2017-01-29 12:25:38 +01:00
parent 970b1a424a
commit 4456f8da57
4 changed files with 27 additions and 22 deletions
+3 -11
View File
@@ -3,11 +3,10 @@ package cmd
import (
"fmt"
"github.com/smira/aptly/api"
"github.com/smira/aptly/utils"
"github.com/smira/commander"
"github.com/smira/flag"
"net/http"
"os"
"golang.org/x/sys/unix"
)
func aptlyAPIServe(cmd *commander.Command, args []string) error {
@@ -26,16 +25,9 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error {
// anything else must fail.
// E.g.: Running the service under a different user may lead to a rootDir
// that exists but is not usable due to access permissions.
// Config loads and returns current configuration
_, err = os.Stat(context.Config().RootDir);
err = utils.DirIsAccessible(context.Config().RootDir)
if err != nil {
if ! os.IsNotExist(err) {
return fmt.Errorf("Something went wrong, %v", err)
}
} else {
if unix.Access(context.Config().RootDir, unix.W_OK) != nil {
return fmt.Errorf("Configured rootDir '%s' is inaccessible, check access rights", context.Config().RootDir)
}
return err
}
listen := context.Flags().Lookup("listen").Value.String()
+2 -10
View File
@@ -12,7 +12,6 @@ import (
"os"
"sort"
"strings"
"golang.org/x/sys/unix"
)
func aptlyServe(cmd *commander.Command, args []string) error {
@@ -29,16 +28,9 @@ func aptlyServe(cmd *commander.Command, args []string) error {
// anything else must fail.
// E.g.: Running the service under a different user may lead to a rootDir
// that exists but is not usable due to access permissions.
// Config loads and returns current configuration
_, err = os.Stat(context.Config().RootDir);
err = utils.DirIsAccessible(context.Config().RootDir)
if err != nil {
if ! os.IsNotExist(err) {
return fmt.Errorf("Something went wrong, %v", err)
}
} else {
if unix.Access(context.Config().RootDir, unix.W_OK) != nil {
return fmt.Errorf("Configured rootDir '%s' is inaccessible, check access rights", context.Config().RootDir)
}
return err
}
if context.CollectionFactory().PublishedRepoCollection().Len() == 0 {
+1 -1
View File
@@ -1 +1 @@
ERROR: Configured rootDir '/root' is inaccessible, check access rights
ERROR: '/root' is inaccessible, check access rights
+21
View File
@@ -1,2 +1,23 @@
// Package utils collects various services: simple operations, compression, etc.
package utils
import (
"fmt"
"os"
"golang.org/x/sys/unix"
)
// check if directory exists and is accessible
func DirIsAccessible(filename string) error {
_, err := os.Stat(filename);
if err != nil {
if ! os.IsNotExist(err) {
return fmt.Errorf("Something went wrong, %v", err)
}
} else {
if unix.Access(filename, unix.W_OK) != nil {
return fmt.Errorf("'%s' is inaccessible, check access rights", filename)
}
}
return nil
}