mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Impl new fn Records::overwrite
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
1047a782e5
commit
df3af9727e
1 changed files with 10 additions and 0 deletions
|
@ -95,6 +95,10 @@ where
|
||||||
.open(path)?,
|
.open(path)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
write_to(file, &mut iter.into_iter())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_to(file: FileLock, iter: &mut dyn Iterator<Item = MetaData>) -> Result<(), Error> {
|
||||||
let writer = io::BufWriter::with_capacity(512, file);
|
let writer = io::BufWriter::with_capacity(512, file);
|
||||||
|
|
||||||
let mut ser = serde_json::Serializer::new(writer);
|
let mut ser = serde_json::Serializer::new(writer);
|
||||||
|
@ -115,6 +119,7 @@ pub fn default_path() -> Result<PathBuf, Error> {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Records {
|
pub struct Records {
|
||||||
file: FileLock,
|
file: FileLock,
|
||||||
|
/// Use BTreeSet to dedup the metadata
|
||||||
data: BTreeSet<MetaData>,
|
data: BTreeSet<MetaData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,4 +149,9 @@ impl Records {
|
||||||
pub fn load() -> Result<Self, Error> {
|
pub fn load() -> Result<Self, Error> {
|
||||||
Self::load_from_path(default_path()?)
|
Self::load_from_path(default_path()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// **Warning: This will overwrite all existing records!**
|
||||||
|
pub fn overwrite(self) -> Result<(), Error> {
|
||||||
|
write_to(self.file, &mut self.data.into_iter())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue