scoop:scoop.platform:0.1.0
src/native/temporary_path.scoop
Selected production source · src/native/temporary_path.scoop
1
package scoop.platform.native3
import scoop.platform.fs.Path4
import scoop.platform.system.OperatingSystem5
import scoop.platform.system.operatingSystem7
/**8
* Builds a temporary-file template from a parent path and validated prefix.9
*/10
public fun temporaryPathPattern(parent: Path, prefix: String): Path {11
requireTemporaryPrefix(prefix)12
return parent.resolve(Path.fromString(prefix + "XXXXXX"))13
}15
internal 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
}26
}