Scoop API

scoop:scoop.asyncio:0.1.0

src/path_metadata.scoop

Selected production source · src/path_metadata.scoop

1package scoop.asyncio
3import scoop.platform.fs.*
4import scoop.platform.native.*
6internal fun takeFileMetadata(pointer: Ptr<Unit>): FileMetadata {
7 @Unsafe
8 {
9 return decodeFileMetadata(nativeTakeMetadata(pointer), 0, None)
10 }
13internal fun metadataResult(result: IoResult): FileMetadata =
14 when (result) {
15 case Metadata(val value) -> value
16 case _ -> throw IllegalStateException(Some("metadata returned no file information"))
17 }
19internal suspend fun metadataOnLoop(
20 loop: LoopOwner,
21 path: Path,
22 followLinks: Boolean
23): 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 -> @Unsafe
35 {
36 return@CallbackOperation path.withIoPath {
37 pointer -> @Unsafe
38 {
39 return@withIoPath nativeStatus(
40 id,
41 nativePathMetadata(native, id, pointer, followLinks)
42 )
43 }
44 }
45 }
46 },
47 {
48 native,
49 id -> @Unsafe
50 {
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 }