Scoop API

scoop:scoop.platform:0.1.0

src/fs/links.scoop

Selected production source · src/fs/links.scoop

1package scoop.platform.fs
3import scoop.platform.system.*
5/**
6 * Creates a symbolic link at this path. On Windows, set targetIsDirectory for directory targets,
7 * including directories that do not yet exist. POSIX ignores this flag.
8 */
9public fun Path.createSymbolicLink(target: Path, targetIsDirectory: Boolean = false) {
10 @Unsafe
11 {
12 this.withPlatformPath {
13 name -> @Unsafe
14 {
15 target.withPlatformPath {
16 destination -> @Unsafe
17 {
18 nativePathSymlink(name, destination, targetIsDirectory).checked(
19 "create symbolic link",
20 Some(this.toOsString())
21 )
22 }
23 }
24 }
25 }
26 }
29/**
30 * Reads the stored target without resolving it. Windows returns the actual symlink or junction
31 * substitute name, with an absolute NT prefix converted to its Win32 spelling.
32 */
33public fun Path.readSymbolicLink(): Path {
34 @Unsafe
35 {
36 return this.withPlatformPath {
37 name -> @Unsafe
38 {
39 return@withPlatformPath nativePathReadlink(name).takePath(
40 "read symbolic link",
41 Some(this.toOsString())
42 )
43 }
44 }
45 }
48/**
49 * Resolves an existing path and its symbolic links into the operating system's canonical absolute
50 * path. Windows retains the extended path prefix returned by the system.
51 */
52public fun Path.canonicalize(): Path {
53 @Unsafe
54 {
55 return this.withPlatformPath {
56 name -> @Unsafe
57 {
58 return@withPlatformPath nativePathCanonical(name).takePath(
59 "canonicalize",
60 Some(this.toOsString())
61 )
62 }
63 }
64 }
67@Extern(name = "scoop_platform_path_symlink_result")
68private fun nativePathSymlink(
69 link: Ptr<Byte>,
70 target: Ptr<Byte>,
71 directory: Boolean
72): NativeFileResult
74@Extern(name = "scoop_platform_path_readlink_result")
75private fun nativePathReadlink(path: Ptr<Byte>): NativeOsString
77@Extern(name = "scoop_platform_path_canonical_result")
78private fun nativePathCanonical(path: Ptr<Byte>): NativeOsString