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.

34 lines
1020 B
Kotlin

package me.eater.hefbrug.platform_utils.`package`
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import me.eater.hefbrug.executor.ExecutionContext
import me.eater.hefbrug.platform_utils.PlatformUtil
abstract class PackageManager(protected val context: ExecutionContext) {
protected val ro = context.roAccess
protected val rw = context.rwAccess
private var hasSynced = false
private var syncLock = Mutex()
abstract suspend fun isInstalled(name: String): Boolean
abstract suspend fun install(name: String)
abstract suspend fun remove(name: String)
protected abstract suspend fun sync()
suspend fun sync(force: Boolean = false) {
syncLock.withLock {
if (!hasSynced || force) {
sync()
hasSynced = true
}
}
}
abstract suspend fun upgrade(name: String)
companion object : PlatformUtil.Provider<PackageManager>(
"package manager",
XbpsManager.Util
)
}