mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-26 13:47:40 +00:00
Fix bugged implementation
This commit is contained in:
+17
-2
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,8 +20,22 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
if unix.Access(context.Config().RootDir, unix.W_OK) != nil {
|
// There are only two working options for aptly's rootDir:
|
||||||
return fmt.Errorf("Configured rootDir '%s' is inaccessible, check access rights", context.Config().RootDir)
|
// 1. rootDir does not exist, then we'll create it
|
||||||
|
// 2. rootDir exists and is writable
|
||||||
|
// 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);
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listen := context.Flags().Lookup("listen").Value.String()
|
listen := context.Flags().Lookup("listen").Value.String()
|
||||||
|
|||||||
+16
-2
@@ -23,8 +23,22 @@ func aptlyServe(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
if unix.Access(context.Config().RootDir, unix.W_OK) != nil {
|
// There are only two working options for aptly's rootDir:
|
||||||
return fmt.Errorf("Configured rootDir '%s' is inaccessible, check access rights", context.Config().RootDir)
|
// 1. rootDir does not exist, then we'll create it
|
||||||
|
// 2. rootDir exists and is writable
|
||||||
|
// 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);
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.CollectionFactory().PublishedRepoCollection().Len() == 0 {
|
if context.CollectionFactory().PublishedRepoCollection().Len() == 0 {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
ERROR: Configured rootDir '/rootDir/does/not/exist' is inaccessible, check access rights
|
ERROR: Configured rootDir '/root' is inaccessible, check access rights
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ class RootDirInaccessible(BaseTest):
|
|||||||
"""
|
"""
|
||||||
fixtureDB = False
|
fixtureDB = False
|
||||||
fixturePool = False
|
fixturePool = False
|
||||||
configOverride = { "rootDir": "/rootDir/does/not/exist" }
|
|
||||||
|
configOverride = {
|
||||||
|
"rootDir": "/root" # any directory that exists but is not writable
|
||||||
|
}
|
||||||
runCmd = "aptly serve -listen=127.0.0.1:8765"
|
runCmd = "aptly serve -listen=127.0.0.1:8765"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user