You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
Kotlin
51 lines
1.5 KiB
Kotlin
package me.eater.hefbrug.platform_utils.`package`
|
|
|
|
import kotlinx.coroutines.sync.Mutex
|
|
import kotlinx.coroutines.sync.withLock
|
|
import me.eater.hefbrug.access.AccessSkeleton
|
|
import me.eater.hefbrug.executor.ExecutionContext
|
|
import me.eater.hefbrug.platform_utils.PlatformUtil
|
|
|
|
class XbpsManager(context: ExecutionContext) : PackageManager(context) {
|
|
private val executionLock = Mutex()
|
|
|
|
override suspend fun isInstalled(name: String): Boolean {
|
|
|
|
return executionLock.withLock {
|
|
ro.execute("xbps-query", name).exitCode == 0
|
|
}
|
|
}
|
|
|
|
override suspend fun install(name: String) {
|
|
executionLock.withLock {
|
|
rw.execute("xbps-install", "-y", name).orThrow()
|
|
}
|
|
}
|
|
|
|
override suspend fun remove(name: String) {
|
|
executionLock.withLock {
|
|
rw.execute("xbps-remove", "-y", name).orThrow()
|
|
}
|
|
}
|
|
|
|
override suspend fun sync() {
|
|
executionLock.withLock {
|
|
rw.execute("xbps-install", "-S").orThrow()
|
|
}
|
|
}
|
|
|
|
override suspend fun upgrade(name: String) {
|
|
executionLock.withLock {
|
|
rw.execute("xbps-install", "-uy", name).orThrow()
|
|
}
|
|
}
|
|
|
|
object Util : PlatformUtil<XbpsManager> {
|
|
override suspend fun isSupported(access: AccessSkeleton): Boolean {
|
|
return access.execute("which", "xbps-install").exitCode == 0 &&
|
|
access.execute("which", "xbps-remove").exitCode == 0
|
|
}
|
|
|
|
override suspend fun getManager(context: ExecutionContext) = XbpsManager(context)
|
|
}
|
|
} |