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 { 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) } }