Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android implementation stuck on roboquant home directory #81

Open
tamuseanmiller opened this issue Jun 22, 2024 · 2 comments
Open

Android implementation stuck on roboquant home directory #81

tamuseanmiller opened this issue Jun 22, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@tamuseanmiller
Copy link

tamuseanmiller commented Jun 22, 2024

Currently attempting to implement a POC of this library into an Android app. Currently, it will fail when doing instrumented tests or running the app when trying to create the home directory. It seems to check for the JVM user.home directory which on Android isn't a valid write spot as app's storage are segmented from the regular phone's storage. Is there any way to pass a custom path instead? Ideally we should be able to pass a custom home directory like /data/data/<package-name>/.roboquant on Android

Here is the stack trace of the failure if it helps:

java.nio.file.FileSystemException: .roboquant: Read-only file system
at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:404)
at java.nio.file.Files.createDirectory(Files.java:674)
at org.roboquant.common.Config$home$2.invoke(Config.kt:150)
at org.roboquant.common.Config$home$2.invoke(Config.kt:147)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at org.roboquant.common.Config.getHome(Config.kt:147)
at org.roboquant.common.Config.getEnv(Config.kt:218)
at org.roboquant.common.Config.getProperty(Config.kt:201)
at org.roboquant.common.Config.getProperty(Config.kt:173)
@jbaron
Copy link
Collaborator

jbaron commented Jun 22, 2024

I guess this is the offending code in the Config class:

val home: Path by lazy {
      val path: Path = Paths.get(System.getProperty("user.home"), ".roboquant")
      if (Files.notExists(path)) {
          Files.createDirectory(path)
          logger.trace { "Created new home directory $path" }
      }
      path
  }

One solution could be to check for another property first (like "roboquant.home") that would supersede this default implementation. Something like:

val home: Path by lazy {
      val roboquantHome = getProperty("roboquant.home")
      val path = if (roboquantHome != null) Paths.get(roboquantHome) else
          Paths.get(System.getProperty("user.home"), ".roboquant")
      if (Files.notExists(path)) {
          Files.createDirectory(path)
          logger.trace { "Created new home directory $path" }
      }
      path
}

@tamuseanmiller
Copy link
Author

I guess this is the offending code in the Config class:

val home: Path by lazy {
      val path: Path = Paths.get(System.getProperty("user.home"), ".roboquant")
      if (Files.notExists(path)) {
          Files.createDirectory(path)
          logger.trace { "Created new home directory $path" }
      }
      path
  }

One solution could be to check for another property first (like "roboquant.home") that would supersede this default implementation. Something like:

val home: Path by lazy {
      val roboquantHome = getProperty("roboquant.home")
      val path = if (roboquantHome != null) Paths.get(roboquantHome) else
          Paths.get(System.getProperty("user.home"), ".roboquant")
      if (Files.notExists(path)) {
          Files.createDirectory(path)
          logger.trace { "Created new home directory $path" }
      }
      path
}

That's a great idea, would just have to update docs for this as well. Much easier than passing a path in for everything that uses the Config class haha.

@jbaron jbaron added the enhancement New feature or request label Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants