pub fn open<P: AsRef<std::path::Path>>(path: P) -> Result<LogFile, LogError> {
        let mut file = AdvisoryFileLock::new(&path, advisory_lock::FileLockMode::Exclusive)?;
        let path = path.as_ref().to_owned();

        let file_size = file.metadata()?.len();
        let mut entries: u64 = 0;
        let mut first_index: u64 = 0;

        if file_size >= 8 {
            first_index = file.read_u64()?;

            let mut pos = 8;

            while file_size - pos > 8 {
                let entry_data_len = file.read_u64()? + 4; // 4 byte checksum

                if file_size - pos - 8 < entry_data_len {
                    // the entry was not fully written
                    break;
                }

                entries += 1;
                pos = file.seek(SeekFrom::Current(entry_data_len.try_into().unwrap()))?;
            }

            file.set_len(pos)?;
        } else {
            file.write_all(&mut [0; 8][..])?;
            file.set_len(8)?;
        }

        Ok(LogFile {
            path,
            file,
            first_index,
            len: entries,
        })
    }
/// Open the log. Takes out an advisory lock.
///
/// This is O(n): we have to iterate to the end of the log in order to clean interrupted writes and determine the length of the log
Open the log. Takes out an advisory lock.
This is O(n): we have to iterate to the end of the log in order to clean interrupted writes and determine the length of the log
Open the log . Takes out an advisory lock . This is O ( n ) : we have to iterate to the end of the log in order to clean interrupted writes and determine the length of the log
pub fn open<P: AsRef<std::path::Path>>(path: P) -> Result<LogFile, LogError> {
        let mut file = AdvisoryFileLock::new(&path, advisory_lock::FileLockMode::Exclusive)?;
        let path = path.as_ref().to_owned();
        let file_size = file.metadata()?.len();
        let mut entries: u64 = 0;
        let mut first_index: u64 = 0;
        if file_size >= 8 {
            first_index = file.read_u64()?;
            let mut pos = 8;
            while file_size - pos > 8 {
                let entry_data_len = file.read_u64()? + 4; // 4 byte checksum
                if file_size - pos - 8 < entry_data_len {
                    // the entry was not fully written
                    break;
                }
                entries += 1;
                pos = file.seek(SeekFrom::Current(entry_data_len.try_into().unwrap()))?;
            }
            file.set_len(pos)?;
        } else {
            file.write_all(&mut [0; 8][..])?;
            file.set_len(8)?;
        }
        Ok(LogFile {
            path,
            file,
            first_index,
            len: entries,
        })
    }
pub fn open < P : AsRef < std :: path :: Path > > ( path : P ) -> Result < LogFile , LogError > { let mut file = AdvisoryFileLock :: new ( & path , advisory_lock :: FileLockMode :: Exclusive ) ? ; let path = path . as_ref ( ) . to_owned ( ) ; let file_size = file . metadata ( ) ? . len ( ) ; let mut entries : u64 = 0 ; let mut first_index : u64 = 0 ; if file_size >= 8 { first_index = file . read_u64 ( ) ? ; let mut pos = 8 ; while file_size - pos > 8 { let entry_data_len = file . read_u64 ( ) ? + 4 ; // 4 byte checksum if file_size - pos - 8 < entry_data_len { // the entry was not fully written break ; } entries += 1 ; pos = file . seek ( SeekFrom :: Current ( entry_data_len . try_into ( ) . unwrap ( ) ) ) ? ; } file . set_len ( pos ) ? ; } else { file . write_all ( & mut [ 0 ; 8 ] [ .. ] ) ? ; file . set_len ( 8 ) ? ; } Ok ( LogFile { path , file , first_index , len : entries , } ) }
Open the log.
Open the log .
path
P