Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar Mailbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Mailbox
Commits
4b0b3cec
Verified
Commit
4b0b3cec
authored
3 years ago
by
Torsten Grote
Browse files
Options
Downloads
Patches
Plain Diff
Create DB dir in subdirectory of mailbox data dir
parent
c75a587d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!22
Create DB dir in subdirectory of mailbox data dir
Pipeline
#7683
passed
3 years ago
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mailbox-cli/src/main/java/org/briarproject/mailbox/cli/JavaCliModule.kt
+34
-21
34 additions, 21 deletions
...c/main/java/org/briarproject/mailbox/cli/JavaCliModule.kt
with
34 additions
and
21 deletions
mailbox-cli/src/main/java/org/briarproject/mailbox/cli/JavaCliModule.kt
+
34
−
21
View file @
4b0b3cec
...
@@ -9,6 +9,7 @@ import org.briarproject.mailbox.core.db.DatabaseConfig
...
@@ -9,6 +9,7 @@ import org.briarproject.mailbox.core.db.DatabaseConfig
import
org.briarproject.mailbox.core.event.DefaultEventExecutorModule
import
org.briarproject.mailbox.core.event.DefaultEventExecutorModule
import
org.briarproject.mailbox.core.system.DefaultTaskSchedulerModule
import
org.briarproject.mailbox.core.system.DefaultTaskSchedulerModule
import
org.briarproject.mailbox.core.tor.JavaTorModule
import
org.briarproject.mailbox.core.tor.JavaTorModule
import
org.briarproject.mailbox.core.util.LogUtils.info
import
org.slf4j.Logger
import
org.slf4j.Logger
import
org.slf4j.LoggerFactory.getLogger
import
org.slf4j.LoggerFactory.getLogger
import
java.io.File
import
java.io.File
...
@@ -37,36 +38,48 @@ internal class JavaCliModule {
...
@@ -37,36 +38,48 @@ internal class JavaCliModule {
private
val
DEFAULT_DATAHOME
=
System
.
getProperty
(
"user.home"
)
+
private
val
DEFAULT_DATAHOME
=
System
.
getProperty
(
"user.home"
)
+
separator
+
".local"
+
separator
+
"share"
separator
+
".local"
+
separator
+
"share"
private
val
DATAHOME_SUBDIR
=
"briar-mailbox"
private
const
val
DATAHOME_SUBDIR
=
"briar-mailbox"
}
}
@Singleton
@Singleton
@Provides
@Provides
fun
provideDatabaseConfig
()
=
object
:
DatabaseConfig
{
fun
provideDatabaseConfig
()
=
object
:
DatabaseConfig
{
override
fun
getDatabaseDirectory
():
File
{
override
fun
getDatabaseDirectory
():
File
{
val
dataHome
=
when
(
val
custom
=
System
.
getenv
(
"XDG_DATA_HOME"
).
orEmpty
())
{
val
dataDir
=
getDataDir
()
""
->
File
(
DEFAULT_DATAHOME
)
val
dbDir
=
File
(
dataDir
,
"db"
)
else
->
File
(
custom
)
if
(!
dbDir
.
exists
()
&&
!
dbDir
.
mkdirs
())
{
}
throw
IOException
(
"dbDir could not be created: ${dbDir.absolutePath}"
)
if
(!
dataHome
.
exists
()
||
!
dataHome
.
isDirectory
())
{
}
else
if
(!
dbDir
.
isDirectory
)
{
throw
IOException
(
"datahome missing or not a directory: ${dataHome.absolutePath}"
)
throw
IOException
(
"dbDir is not a directory: ${dbDir.absolutePath}"
)
}
val
dataDir
=
File
(
dataHome
.
absolutePath
+
separator
+
DATAHOME_SUBDIR
)
if
(!
dataDir
.
exists
()
&&
!
dataDir
.
mkdirs
())
{
throw
IOException
(
"datadir could not be created: ${dataDir.absolutePath}"
)
}
else
if
(!
dataDir
.
isDirectory
())
{
throw
IOException
(
"datadir is not a directory: ${dataDir.absolutePath}"
)
}
}
return
dbDir
}
}
val
perms
=
HashSet
<
PosixFilePermission
>()
private
fun
getDataDir
():
File
{
perms
.
add
(
OWNER_READ
)
val
dataHome
=
when
(
val
custom
=
System
.
getenv
(
"XDG_DATA_HOME"
).
orEmpty
())
{
perms
.
add
(
OWNER_WRITE
)
""
->
File
(
DEFAULT_DATAHOME
)
perms
.
add
(
OWNER_EXECUTE
)
else
->
File
(
custom
)
setPosixFilePermissions
(
dataDir
.
toPath
(),
perms
)
}
if
(!
dataHome
.
exists
()
||
!
dataHome
.
isDirectory
)
{
throw
IOException
(
"datahome missing or not a directory: ${dataHome.absolutePath}"
)
}
LOG
.
info
(
"Datadir set to: "
+
dataDir
.
absolutePath
)
val
dataDir
=
File
(
dataHome
.
absolutePath
+
separator
+
DATAHOME_SUBDIR
)
return
dataDir
if
(!
dataDir
.
exists
()
&&
!
dataDir
.
mkdirs
())
{
throw
IOException
(
"datadir could not be created: ${dataDir.absolutePath}"
)
}
else
if
(!
dataDir
.
isDirectory
)
{
throw
IOException
(
"datadir is not a directory: ${dataDir.absolutePath}"
)
}
}
val
perms
=
HashSet
<
PosixFilePermission
>()
perms
.
add
(
OWNER_READ
)
perms
.
add
(
OWNER_WRITE
)
perms
.
add
(
OWNER_EXECUTE
)
setPosixFilePermissions
(
dataDir
.
toPath
(),
perms
)
LOG
.
info
{
"Datadir set to: ${dataDir.absolutePath}"
}
return
dataDir
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment