scoop:scoop.platform:0.1.0
src/fs/links.scoop
Selected production source · src/fs/links.scoop
1
package scoop.platform.fs3
import 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
*/9
public fun Path.createSymbolicLink(target: Path, targetIsDirectory: Boolean = false) {10
@Unsafe11
{12
this.withPlatformPath {13
name -> @Unsafe14
{15
target.withPlatformPath {16
destination -> @Unsafe17
{18
nativePathSymlink(name, destination, targetIsDirectory).checked(19
"create symbolic link",20
Some(this.toOsString())21
)22
}23
}24
}25
}26
}27
}29
/**30
* Reads the stored target without resolving it. Windows returns the actual symlink or junction31
* substitute name, with an absolute NT prefix converted to its Win32 spelling.32
*/33
public fun Path.readSymbolicLink(): Path {34
@Unsafe35
{36
return this.withPlatformPath {37
name -> @Unsafe38
{39
return@withPlatformPath nativePathReadlink(name).takePath(40
"read symbolic link",41
Some(this.toOsString())42
)43
}44
}45
}46
}48
/**49
* Resolves an existing path and its symbolic links into the operating system's canonical absolute50
* path. Windows retains the extended path prefix returned by the system.51
*/52
public fun Path.canonicalize(): Path {53
@Unsafe54
{55
return this.withPlatformPath {56
name -> @Unsafe57
{58
return@withPlatformPath nativePathCanonical(name).takePath(59
"canonicalize",60
Some(this.toOsString())61
)62
}63
}64
}65
}67
@Extern(name = "scoop_platform_path_symlink_result")68
private fun nativePathSymlink(69
link: Ptr<Byte>,70
target: Ptr<Byte>,71
directory: Boolean72
): NativeFileResult74
@Extern(name = "scoop_platform_path_readlink_result")75
private fun nativePathReadlink(path: Ptr<Byte>): NativeOsString77
@Extern(name = "scoop_platform_path_canonical_result")78
private fun nativePathCanonical(path: Ptr<Byte>): NativeOsString