mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-25 05:22:52 +00:00
feat: extract package implementation (#1647)
* feat: extract registry implementation * feat: tinymist package * fix: guard * fix: guard 2 * feat: no specifier * fix: temp_dir_in impl * fix: impls * feat: UniversePack::new * feat: clone into memory * feat: implement some pack for testing * build: update cargo.lock * feat: fit for web * fix: guard
This commit is contained in:
parent
9d1007a4f3
commit
84c211c7eb
24 changed files with 796 additions and 68 deletions
|
|
@ -220,6 +220,23 @@ pub fn write_atomic<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Res
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Creates a temporary directory in the given path and calls the given
|
||||
/// function.
|
||||
///
|
||||
/// The temporary directory is automatically destroyed after the function
|
||||
/// returns, even if it panics.
|
||||
///
|
||||
/// Note: it may leak if the process is killed.
|
||||
pub fn temp_dir_in<P: AsRef<Path>, T>(path: P, f: impl FnOnce(&Path) -> Result<T>) -> Result<T> {
|
||||
let path = path.as_ref();
|
||||
|
||||
std::fs::create_dir_all(path)
|
||||
.with_context(|| format!("failed to create directory for tmpdir `{}`", path.display()))?;
|
||||
|
||||
let tmp = TempFileBuilder::new().tempdir_in(path)?;
|
||||
f(tmp.path())
|
||||
}
|
||||
|
||||
/// Equivalent to [`write()`], but does not write anything if the file contents
|
||||
/// are identical to the given contents.
|
||||
pub fn write_if_changed<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue