pub(crate) fn compact(&self) -> Result<(), Error> {
        let metadata = self.metadata_most_recent()?;

        let tmp_dir = tempfile::tempdir().map_err(Error::CompactTempDir)?;
        let tmp_path = tmp_dir.path().join(INDEX_FILE_NAME);

        // In its own scope so the file will be flushed when the scope is closed.
        {
            let tmp_file = std::fs::OpenOptions::new()
                .append(true)
                .create(true)
                .open(&tmp_path)
                .map_err(Error::CompactTempFile)?;

            let builder = csv::WriterBuilder::new();
            let mut writer = builder.from_writer(tmp_file);

            for entry in metadata {
                writer.serialize(&entry).map_err(Error::SerializeMetadata)?;
            }
        }

        let index_file_path = self.folder_path.join(INDEX_FILE_NAME);
        std::fs::copy(tmp_path, index_file_path).map_err(Error::MoveCompactTempFile)?;

        std::fs::remove_dir_all(self.folder_path.join(IDENTIFIER_FOLDER_NAME))
            .map_err(Error::CleanupIdentifierFolder)?;

        Ok(())
    }
/// Compact files into singular index file and only keep latest state of
/// entries.
Compact files into singular index file and only keep latest state of
entries.
Compact files into singular index file and only keep latest state of entries .
pub(crate) fn compact(&self) -> Result<(), Error> {
        let metadata = self.metadata_most_recent()?;
        let tmp_dir = tempfile::tempdir().map_err(Error::CompactTempDir)?;
        let tmp_path = tmp_dir.path().join(INDEX_FILE_NAME);
        // In its own scope so the file will be flushed when the scope is closed.
        {
            let tmp_file = std::fs::OpenOptions::new()
                .append(true)
                .create(true)
                .open(&tmp_path)
                .map_err(Error::CompactTempFile)?;
            let builder = csv::WriterBuilder::new();
            let mut writer = builder.from_writer(tmp_file);
            for entry in metadata {
                writer.serialize(&entry).map_err(Error::SerializeMetadata)?;
            }
        }
        let index_file_path = self.folder_path.join(INDEX_FILE_NAME);
        std::fs::copy(tmp_path, index_file_path).map_err(Error::MoveCompactTempFile)?;
        std::fs::remove_dir_all(self.folder_path.join(IDENTIFIER_FOLDER_NAME))
            .map_err(Error::CleanupIdentifierFolder)?;
        Ok(())
    }
pub ( crate ) fn compact ( & self ) -> Result < ( ) , Error > { let metadata = self . metadata_most_recent ( ) ? ; let tmp_dir = tempfile :: tempdir ( ) . map_err ( Error :: CompactTempDir ) ? ; let tmp_path = tmp_dir . path ( ) . join ( INDEX_FILE_NAME ) ; // In its own scope so the file will be flushed when the scope is closed. { let tmp_file = std :: fs :: OpenOptions :: new ( ) . append ( true ) . create ( true ) . open ( & tmp_path ) . map_err ( Error :: CompactTempFile ) ? ; let builder = csv :: WriterBuilder :: new ( ) ; let mut writer = builder . from_writer ( tmp_file ) ; for entry in metadata { writer . serialize ( & entry ) . map_err ( Error :: SerializeMetadata ) ? ; } } let index_file_path = self . folder_path . join ( INDEX_FILE_NAME ) ; std :: fs :: copy ( tmp_path , index_file_path ) . map_err ( Error :: MoveCompactTempFile ) ? ; std :: fs :: remove_dir_all ( self . folder_path . join ( IDENTIFIER_FOLDER_NAME ) ) . map_err ( Error :: CleanupIdentifierFolder ) ? ; Ok ( ( ) ) }
Compact files into singular index file and only keep latest state of
entries.
Compact files into singular index file and only keep latest state of entries .
&self
&self