scoop:scoop.asyncio:0.1.0
src/path_metadata.scoop
Selected production source · src/path_metadata.scoop
1
package scoop.asyncio3
import scoop.platform.fs.*4
import scoop.platform.native.*6
internal fun takeFileMetadata(pointer: Ptr<Unit>): FileMetadata {7
@Unsafe8
{9
return decodeFileMetadata(nativeTakeMetadata(pointer), 0, None)10
}11
}13
internal fun metadataResult(result: IoResult): FileMetadata =14
when (result) {15
case Metadata(val value) -> value16
case _ -> throw IllegalStateException(Some("metadata returned no file information"))17
}19
internal suspend fun metadataOnLoop(20
loop: LoopOwner,21
path: Path,22
followLinks: Boolean23
): FileMetadata {24
val job = loop.requireJob()25
val context = path.toOsString()26
return suspendCoroutine<FileMetadata> {27
continuation ->28
val operation =29
CallbackOperation(30
loop,31
loop.nextOperation(),32
{33
native,34
id -> @Unsafe35
{36
return@CallbackOperation path.withIoPath {37
pointer -> @Unsafe38
{39
return@withIoPath nativeStatus(40
id,41
nativePathMetadata(native, id, pointer, followLinks)42
)43
}44
}45
}46
},47
{48
native,49
id -> @Unsafe50
{51
nativeWorkCancel(native, id)52
}53
},54
{55
event,56
selected -> when (57
completionFailure("metadata", event.result, selected, Some(context))58
) {59
case Some(val error) -> continuation.resumeWithException(error)60
case None -> continuation.resume(metadataResult(event.result))61
}62
}63
)64
operation.subscribe(job)65
loop.submit(operation)66
}67
}