Scoop API

scoop:scoop.platform:0.1.0

src/native/temporary_path.scoop

Selected production source · src/native/temporary_path.scoop

1package scoop.platform.native
3import scoop.platform.fs.Path
4import scoop.platform.system.OperatingSystem
5import scoop.platform.system.operatingSystem
7/**
8 * Builds a temporary-file template from a parent path and validated prefix.
9 */
10public fun temporaryPathPattern(parent: Path, prefix: String): Path {
11 requireTemporaryPrefix(prefix)
12 return parent.resolve(Path.fromString(prefix + "XXXXXX"))
15internal fun requireTemporaryPrefix(prefix: String) {
16 for (byte in prefix.toByteArray()) {
17 if (
18 byte ==
19 0 ||
20 byte ==
21 47 ||
22 (operatingSystem == OperatingSystem.Windows && (byte == 92 || byte == 58))
23 )
24 throw IllegalArgumentException(Some("invalid temporary path prefix"))
25 }