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
c75a587d
Commit
c75a587d
authored
3 years ago
by
Torsten Grote
Browse files
Options
Downloads
Plain Diff
Merge branch '36-cliapp-data-in-linux-dir' into 'main'
Provide the typical dir for storing data Closes
#36
See merge request
!18
parents
37b77b35
a9774a15
No related branches found
No related tags found
1 merge request
!18
Provide the typical dir for storing data
Pipeline
#7681
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mailbox-cli/src/main/java/org/briarproject/mailbox/cli/JavaCliModule.kt
+41
-2
41 additions, 2 deletions
...c/main/java/org/briarproject/mailbox/cli/JavaCliModule.kt
with
41 additions
and
2 deletions
mailbox-cli/src/main/java/org/briarproject/mailbox/cli/JavaCliModule.kt
+
41
−
2
View file @
c75a587d
...
...
@@ -9,7 +9,16 @@ import org.briarproject.mailbox.core.db.DatabaseConfig
import
org.briarproject.mailbox.core.event.DefaultEventExecutorModule
import
org.briarproject.mailbox.core.system.DefaultTaskSchedulerModule
import
org.briarproject.mailbox.core.tor.JavaTorModule
import
org.slf4j.Logger
import
org.slf4j.LoggerFactory.getLogger
import
java.io.File
import
java.io.File.separator
import
java.io.IOException
import
java.nio.file.Files.setPosixFilePermissions
import
java.nio.file.attribute.PosixFilePermission
import
java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE
import
java.nio.file.attribute.PosixFilePermission.OWNER_READ
import
java.nio.file.attribute.PosixFilePermission.OWNER_WRITE
import
javax.inject.Singleton
@Module
(
...
...
@@ -22,12 +31,42 @@ import javax.inject.Singleton
)
@InstallIn
(
SingletonComponent
::
class
)
internal
class
JavaCliModule
{
companion
object
{
private
val
LOG
:
Logger
=
getLogger
(
JavaCliModule
::
class
.
java
)
private
val
DEFAULT_DATAHOME
=
System
.
getProperty
(
"user.home"
)
+
separator
+
".local"
+
separator
+
"share"
private
val
DATAHOME_SUBDIR
=
"briar-mailbox"
}
@Singleton
@Provides
fun
provideDatabaseConfig
()
=
object
:
DatabaseConfig
{
override
fun
getDatabaseDirectory
():
File
{
// TODO: use a correct location
return
File
(
"/tmp"
)
val
dataHome
=
when
(
val
custom
=
System
.
getenv
(
"XDG_DATA_HOME"
).
orEmpty
())
{
""
->
File
(
DEFAULT_DATAHOME
)
else
->
File
(
custom
)
}
if
(!
dataHome
.
exists
()
||
!
dataHome
.
isDirectory
())
{
throw
IOException
(
"datahome missing or not a directory: ${dataHome.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}"
)
}
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