diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands/Tinc.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt index 91a2678..5116d63 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -8,22 +8,16 @@ import java.io.IOException | |||
8 | */ | 8 | */ |
9 | object Tinc { | 9 | object Tinc { |
10 | 10 | ||
11 | private fun newCommand(netName: String): Command = | 11 | private fun newCommand(netConf: AppPaths.NetConf): Command = |
12 | Command(AppPaths.tinc().absolutePath) | 12 | Command(AppPaths.tinc().absolutePath) |
13 | .withOption("config", AppPaths.confDir(netName).absolutePath) | 13 | .withOption("config", AppPaths.confDir(netConf).absolutePath) |
14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) | 14 | .withOption("pidfile", AppPaths.pidFile(netConf).absolutePath) |
15 | 15 | ||
16 | // independently runnable commands | 16 | // independently runnable commands |
17 | 17 | ||
18 | @Throws(IOException::class) | 18 | @Throws(IOException::class) |
19 | fun network(): List<String> = | 19 | fun fsck(netConf: AppPaths.NetConf, fix: Boolean): List<String> { |
20 | Executor.call(Command(AppPaths.tinc().absolutePath) | 20 | var cmd = newCommand(netConf).withArguments("fsck") |
21 | .withOption("config", AppPaths.confDir().absolutePath) | ||
22 | .withArguments("network")) | ||
23 | |||
24 | @Throws(IOException::class) | ||
25 | fun fsck(netName: String, fix: Boolean): List<String> { | ||
26 | var cmd = newCommand(netName).withArguments("fsck") | ||
27 | if (fix) cmd = cmd.withOption("force") | 21 | if (fix) cmd = cmd.withOption("force") |
28 | return Executor.call(cmd) | 22 | return Executor.call(cmd) |
29 | } | 23 | } |
@@ -31,18 +25,18 @@ object Tinc { | |||
31 | // commands requiring a running tinc daemon | 25 | // commands requiring a running tinc daemon |
32 | 26 | ||
33 | @Throws(IOException::class) | 27 | @Throws(IOException::class) |
34 | fun stop(netName: String) { | 28 | fun stop(netConf: AppPaths.NetConf) { |
35 | Executor.call(newCommand(netName).withArguments("stop")) | 29 | Executor.call(newCommand(netConf).withArguments("stop")) |
36 | } | 30 | } |
37 | 31 | ||
38 | @Throws(IOException::class) | 32 | @Throws(IOException::class) |
39 | fun dumpNodes(netName: String, reachable: Boolean): List<String> = | 33 | fun dumpNodes(netConf: AppPaths.NetConf, reachable: Boolean): List<String> = |
40 | Executor.call( | 34 | Executor.call( |
41 | if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") | 35 | if (reachable) newCommand(netConf).withArguments("dump", "reachable", "nodes") |
42 | else newCommand(netName).withArguments("dump", "nodes")) | 36 | else newCommand(netConf).withArguments("dump", "nodes")) |
43 | 37 | ||
44 | @Throws(IOException::class) | 38 | @Throws(IOException::class) |
45 | fun info(netName: String, node: String): String = | 39 | fun info(netConf: AppPaths.NetConf, node: String): String = |
46 | Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n") | 40 | Executor.call(newCommand(netConf).withArguments("info", node)).joinToString("\n") |
47 | 41 | ||
48 | } | 42 | } |