Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions internal/configuration/setup/Setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -717,15 +718,15 @@ type setupView struct {

func (v *setupView) loadFromConfig() {
v.IsInitialSetup = isInitialSetup
env := environment.New()
if environment.IsDockerInstance() {
v.IsDocker = true
v.IsDataNotMounted = !isVolumeMounted("/app/data")
v.IsConfigNotMounted = !isVolumeMounted("/app/config")
v.IsDataNotMounted = !isVolumeMounted(env.DataDir)
v.IsConfigNotMounted = !isVolumeMounted(env.ConfigDir)
}
v.HasAwsFeature = aws.IsIncludedInBuild
v.ProtectedUrls = protectedUrls
if isInitialSetup {
env := environment.New()
v.MinPasswordLength = env.MinLengthPassword
v.CloudSettings, _ = cloudconfig.Load()
v.S3EnvProvided = env.IsAwsProvided()
Expand All @@ -748,7 +749,6 @@ func (v *setupView) loadFromConfig() {
} else {
v.Port = environment.DefaultPort
}
env := environment.New()
v.S3EnvProvided = env.IsAwsProvided()
v.MinPasswordLength = env.MinLengthPassword

Expand All @@ -757,19 +757,29 @@ func (v *setupView) loadFromConfig() {
v.DatabaseSettings = dbSettings
}

func isVolumeMounted(path string) bool {
func isVolumeMounted(dir string) bool {
file, err := os.Open("/proc/mounts")
if err != nil {
fmt.Println(err)
return false
}
defer file.Close()
return isPathMounted(file, dir)
}

scanner := bufio.NewScanner(file)
func isPathMounted(mounts io.Reader, dir string) bool {
if !path.IsAbs(dir) {
dir = path.Join("/app", dir)
}
dir = path.Clean(dir)
scanner := bufio.NewScanner(mounts)
for scanner.Scan() {
line := scanner.Text()
fields := strings.Fields(line)
if len(fields) > 1 && fields[1] == path {
fields := strings.Fields(scanner.Text())
if len(fields) < 2 {
continue
}
mountPath := path.Clean(fields[1])
if mountPath != "/" && (dir == mountPath || strings.HasPrefix(dir, mountPath+"/")) {
return true
}
}
Expand Down
11 changes: 11 additions & 0 deletions internal/configuration/setup/Setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ func TestAddTrailingSlash(t *testing.T) {
test.IsEqualString(t, addTrailingSlash("test2/"), "test2/")
}

func TestIsPathMounted(t *testing.T) {
mounts := strings.NewReader("overlay / overlay rw 0 0\n/dev/vda /mnt_vol ext4 rw 0 0\n")
test.IsEqualBool(t, isPathMounted(mounts, "/mnt_vol/data"), true)

mounts = strings.NewReader("overlay / overlay rw 0 0\n/dev/vdb /app/data ext4 rw 0 0\n")
test.IsEqualBool(t, isPathMounted(mounts, "data"), true)

mounts = strings.NewReader("overlay / overlay rw 0 0\n")
test.IsEqualBool(t, isPathMounted(mounts, "/mnt_vol/data"), false)
}

func TestError(t *testing.T) {
w := httptest.NewRecorder()
outputError(w, errors.New("test error"))
Expand Down
Loading