2011-11-08 22:35:15 -06:00
|
|
|
/*
|
|
|
|
Module: tempfile
|
|
|
|
|
|
|
|
Temporary files and directories
|
|
|
|
*/
|
|
|
|
|
2011-12-13 18:25:51 -06:00
|
|
|
import core::option;
|
2011-11-08 22:35:15 -06:00
|
|
|
import fs;
|
|
|
|
import option::{none, some};
|
|
|
|
import rand;
|
|
|
|
|
2011-12-06 15:58:45 -06:00
|
|
|
/*
|
|
|
|
Function: mkdtemp
|
|
|
|
*/
|
2011-11-08 22:35:15 -06:00
|
|
|
fn mkdtemp(prefix: str, suffix: str) -> option::t<str> {
|
|
|
|
let r = rand::mk_rng();
|
|
|
|
let i = 0u;
|
|
|
|
while (i < 1000u) {
|
|
|
|
let s = prefix + r.gen_str(16u) + suffix;
|
2011-11-22 18:11:03 -06:00
|
|
|
if fs::make_dir(s, 0x1c0i32) { // FIXME: u+rwx
|
2011-11-08 22:35:15 -06:00
|
|
|
ret some(s);
|
|
|
|
}
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret none;
|
|
|
|
}
|