【发布时间】:2023-01-11 06:43:35
【问题描述】:
创建用于套接字使用的临时文件时出错:
Error: Custom { kind: AlreadyExists, error: PathError { path: "/tmp", err: Custom { kind: AlreadyExists, error: "too many temporary files exist" } } }
use tempfile::{tempfile, Builder, NamedTempFile};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let file = Builder::new().prefix("testsock").rand_bytes(0).tempfile()?;
Ok(())
}
有什么办法可以覆盖该文件吗?
【问题讨论】:
-
既然设置了
rand_bytes (0),为什么还要用tempfile?tempfile的全部意义在于文件名的一部分是随机生成的。如果你想要一个固定的名字,直接使用File。
标签: rust temporary-files rust-tokio