Skip to content

Commit

Permalink
Merge pull request #7 from khaller93/hotfix/no-toload-permission-issue
Browse files Browse the repository at this point in the history
Solves the bug #6, where running a container with a non-root users fail, if a repository initialization has a configuration, but no data to load (i.e. a non-existing toLoad folder).

The entry script creates now the temporary toLoad folder in case a repository misses it and changes its ownership accordingly.
  • Loading branch information
khaller93 authored May 18, 2023
2 parents 1999ad8 + 38f3c73 commit 26fb50e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
3 changes: 3 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ set -e

USER="${GDB_USER:=root}"

mkdir -p /repository.init
mkdir -p /tmp/toLoad.tmp

if [ "$USER" != "root" -a "$USER" != "0" ]; then
if [ $(expr "$USER" : "^[0-9]*$") -eq 0 ]; then
USER_PWD=$(cat /etc/passwd | grep -e "^$USER:" || true)
Expand Down
14 changes: 1 addition & 13 deletions graphdb-repository-init/repo_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func assembleToLoadFolderPath(repositoryDirectory string) string {
fmt.Printf("%s Warning: Couldn't find data to load for '%s'. 'toLoad' is missing.\n",
LogPrefix, repositoryDirectory)
}
p := "/tmp/graphdb/toLoad"
p := "/tmp/toLoad.tmp"
err := os.MkdirAll(p, os.ModeDir)
if err != nil {
fmt.Printf("%s Warning: Couldn't create temporary folder '%s': %s\n",
Expand All @@ -55,16 +55,6 @@ func assembleToLoadFolderPath(repositoryDirectory string) string {
return p
}

// cleanTemporaryLoadFolder cleans the temporary folder, if it has been created.
func cleanTemporaryLoadFolder(toLoadFolder string) {
if toLoadFolder == "/tmp/graphdb/toLoad" {
err := os.RemoveAll("/tmp/graphdb/toLoad")
if err != nil {
fmt.Printf("%s Warning: Couldn't delete temporary 'toLoad' folder. %s\n", LogPrefix, err.Error())
}
}
}

// InitRepository initializes the repository configured in the given directory. returns true,
// if the repository could be initialized, otherwise false.
func InitRepository(repositoryDirectory string) bool {
Expand Down Expand Up @@ -95,12 +85,10 @@ func InitRepository(repositoryDirectory string) bool {
fmt.Printf("%s Error: Failed to write the lock for a new initialization. %s",
LogPrefix, err.Error())
}
cleanTemporaryLoadFolder(toLoadFolder)
return true
} else {
fmt.Printf("%s Error: Execution of %s command failed. %s\n", LogPrefix, PreloadTool,
err.Error())
cleanTemporaryLoadFolder(toLoadFolder)
}
} else {
fmt.Printf("%s Error: Could not find config.ttl for '%s'. %s\n", LogPrefix, repositoryDirectory,
Expand Down
6 changes: 2 additions & 4 deletions set-ownership.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ fi
USER=$1

chown $USER -R /opt/graphdb

if [ -d "/repository.init" ]; then
chown $USER -R /repository.init || true
fi
chown $USER -R /tmp/toLoad.tmp || true
chown $USER -R /repository.init --quiet || true

0 comments on commit 26fb50e

Please sign in to comment.