From 93d5d779521b07ae2b655f4919882344072027f3 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 12 Feb 2019 12:05:33 +0100 Subject: [PATCH] rename ArchiveIndex to DynamicIndex also changed the file extension from .aidx to .didx --- src/api2/admin/datastore/catar.rs | 18 ++++---- src/backup.rs | 2 +- src/backup/datastore.rs | 18 ++++---- .../{archive_index.rs => dynamic_index.rs} | 46 +++++++++---------- 4 files changed, 42 insertions(+), 42 deletions(-) rename src/backup/{archive_index.rs => dynamic_index.rs} (92%) diff --git a/src/api2/admin/datastore/catar.rs b/src/api2/admin/datastore/catar.rs index 883cfbbb..45c6f44a 100644 --- a/src/api2/admin/datastore/catar.rs +++ b/src/api2/admin/datastore/catar.rs @@ -3,7 +3,7 @@ use failure::*; use crate::tools; use crate::tools::wrapped_reader_stream::*; use crate::backup::datastore::*; -use crate::backup::archive_index::*; +use crate::backup::dynamic_index::*; //use crate::server::rest::*; use crate::api::schema::*; use crate::api::router::*; @@ -21,7 +21,7 @@ use hyper::http::request::Parts; pub struct UploadCaTar { stream: Body, - index: ArchiveIndexWriter, + index: DynamicIndexWriter, count: usize, } @@ -62,7 +62,7 @@ fn upload_catar( let backup_id = tools::required_string_param(¶m, "id")?; let backup_time = tools::required_integer_param(¶m, "time")?; - println!("Upload {}.catar to {} ({}/{}/{}/{}.aidx)", archive_name, store, + println!("Upload {}.catar to {} ({}/{}/{}/{}.didx)", archive_name, store, backup_type, backup_id, backup_time, archive_name); let content_type = parts.headers.get(http::header::CONTENT_TYPE) @@ -79,11 +79,11 @@ fn upload_catar( let mut path = datastore.create_backup_dir(backup_type, backup_id, backup_time)?; let mut full_archive_name = PathBuf::from(archive_name); - full_archive_name.set_extension("aidx"); + full_archive_name.set_extension("didx"); path.push(full_archive_name); - let index = datastore.create_archive_writer(path, chunk_size)?; + let index = datastore.create_dynamic_writer(path, chunk_size)?; let upload = UploadCaTar { stream: req_body, index, count: 0}; @@ -131,7 +131,7 @@ fn download_catar( let backup_time = tools::required_integer_param(¶m, "time")?; let backup_time = Utc.timestamp(backup_time, 0); - println!("Download {}.catar from {} ({}/{}/{}/{}.aidx)", archive_name, store, + println!("Download {}.catar from {} ({}/{}/{}/{}.didx)", archive_name, store, backup_type, backup_id, backup_time, archive_name); let datastore = DataStore::lookup_datastore(store)?; @@ -139,12 +139,12 @@ fn download_catar( let mut path = datastore.get_backup_dir(backup_type, backup_id, backup_time); let mut full_archive_name = PathBuf::from(archive_name); - full_archive_name.set_extension("aidx"); + full_archive_name.set_extension("didx"); path.push(full_archive_name); - let index = datastore.open_archive_reader(path)?; - let reader = BufferedArchiveReader::new(index); + let index = datastore.open_dynamic_reader(path)?; + let reader = BufferedDynamicReader::new(index); let stream = WrappedReaderStream::new(reader); // fixme: set size, content type? diff --git a/src/backup.rs b/src/backup.rs index 28054bc1..e38cb194 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -3,5 +3,5 @@ pub mod chunker; pub mod chunk_store; pub mod fixed_index; -pub mod archive_index; +pub mod dynamic_index; pub mod datastore; diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 0206b7ec..027aa9ce 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -11,7 +11,7 @@ use crate::tools; use crate::config::datastore; use super::chunk_store::*; use super::fixed_index::*; -use super::archive_index::*; +use super::dynamic_index::*; use chrono::{Utc, TimeZone}; @@ -89,20 +89,20 @@ impl DataStore { Ok(index) } - pub fn create_archive_writer>( + pub fn create_dynamic_writer>( &self, filename: P, chunk_size: usize - ) -> Result { + ) -> Result { - let index = ArchiveIndexWriter::create( + let index = DynamicIndexWriter::create( self.chunk_store.clone(), filename.as_ref(), chunk_size)?; Ok(index) } - pub fn open_archive_reader>(&self, filename: P) -> Result { + pub fn open_dynamic_reader>(&self, filename: P) -> Result { - let index = ArchiveIndexReader::open(self.chunk_store.clone(), filename.as_ref())?; + let index = DynamicIndexReader::open(self.chunk_store.clone(), filename.as_ref())?; Ok(index) } @@ -216,7 +216,7 @@ impl DataStore { if let Some(ext) = path.extension() { if ext == "fidx" { list.push(path); - } else if ext == "aidx" { + } else if ext == "didx" { list.push(path); } } @@ -234,8 +234,8 @@ impl DataStore { if ext == "fidx" { let index = self.open_fixed_reader(&path)?; index.mark_used_chunks(status)?; - } else if ext == "aidx" { - let index = self.open_archive_reader(&path)?; + } else if ext == "didx" { + let index = self.open_dynamic_reader(&path)?; index.mark_used_chunks(status)?; } } diff --git a/src/backup/archive_index.rs b/src/backup/dynamic_index.rs similarity index 92% rename from src/backup/archive_index.rs rename to src/backup/dynamic_index.rs index c991d1a2..aec318e3 100644 --- a/src/backup/archive_index.rs +++ b/src/backup/dynamic_index.rs @@ -14,7 +14,7 @@ use uuid::Uuid; #[repr(C)] //pub struct DynamicIndexHeader { -pub struct ArchiveIndexHeader { +pub struct DynamicIndexHeader { pub magic: [u8; 12], pub version: u32, pub uuid: [u8; 16], @@ -23,7 +23,7 @@ pub struct ArchiveIndexHeader { } -pub struct ArchiveIndexReader { +pub struct DynamicIndexReader { store: Arc, _file: File, pub size: usize, @@ -35,9 +35,9 @@ pub struct ArchiveIndexReader { } // fixme: ???!!! -unsafe impl Send for ArchiveIndexReader {} +unsafe impl Send for DynamicIndexReader {} -impl Drop for ArchiveIndexReader { +impl Drop for DynamicIndexReader { fn drop(&mut self) { if let Err(err) = self.unmap() { @@ -46,7 +46,7 @@ impl Drop for ArchiveIndexReader { } } -impl ArchiveIndexReader { +impl DynamicIndexReader { pub fn open(store: Arc, path: &Path) -> Result { @@ -54,7 +54,7 @@ impl ArchiveIndexReader { let mut file = std::fs::File::open(&full_path)?; - let header_size = std::mem::size_of::(); + let header_size = std::mem::size_of::(); // todo: use static assertion when available in rust if header_size != 4096 { bail!("got unexpected header size for {:?}", path); } @@ -62,9 +62,9 @@ impl ArchiveIndexReader { let mut buffer = vec![0u8; header_size]; file.read_exact(&mut buffer)?; - let header = unsafe { &mut * (buffer.as_ptr() as *mut ArchiveIndexHeader) }; + let header = unsafe { &mut * (buffer.as_ptr() as *mut DynamicIndexHeader) }; - if header.magic != *b"PROXMOX-AIDX" { + if header.magic != *b"PROXMOX-DIDX" { bail!("got unknown magic number for {:?}", path); } @@ -193,8 +193,8 @@ impl ArchiveIndexReader { } } -pub struct BufferedArchiveReader { - index: ArchiveIndexReader, +pub struct BufferedDynamicReader { + index: DynamicIndexReader, archive_size: u64, read_buffer: Vec, buffered_chunk_idx: usize, @@ -202,9 +202,9 @@ pub struct BufferedArchiveReader { read_offset: u64, } -impl BufferedArchiveReader { +impl BufferedDynamicReader { - pub fn new(index: ArchiveIndexReader) -> Self { + pub fn new(index: DynamicIndexReader) -> Self { let archive_size = index.chunk_end(index.index_entries - 1); Self { @@ -233,7 +233,7 @@ impl BufferedArchiveReader { } } -impl crate::tools::BufferedReader for BufferedArchiveReader { +impl crate::tools::BufferedReader for BufferedDynamicReader { fn buffered_read(&mut self, offset: u64) -> Result<&[u8], Error> { @@ -272,7 +272,7 @@ impl crate::tools::BufferedReader for BufferedArchiveReader { } -impl std::io::Read for BufferedArchiveReader { +impl std::io::Read for BufferedDynamicReader { fn read(&mut self, buf: &mut [u8]) -> Result { @@ -294,7 +294,7 @@ impl std::io::Read for BufferedArchiveReader { } } -impl std::io::Seek for BufferedArchiveReader { +impl std::io::Seek for BufferedDynamicReader { fn seek(&mut self, pos: std::io::SeekFrom) -> Result { @@ -318,7 +318,7 @@ impl std::io::Seek for BufferedArchiveReader { } } -pub struct ArchiveIndexWriter { +pub struct DynamicIndexWriter { store: Arc, chunker: Chunker, writer: BufWriter, @@ -333,20 +333,20 @@ pub struct ArchiveIndexWriter { chunk_buffer: Vec, } -impl Drop for ArchiveIndexWriter { +impl Drop for DynamicIndexWriter { fn drop(&mut self) { let _ = std::fs::remove_file(&self.tmp_filename); // ignore errors } } -impl ArchiveIndexWriter { +impl DynamicIndexWriter { pub fn create(store: Arc, path: &Path, chunk_size: usize) -> Result { let full_path = store.relative_path(path); let mut tmp_path = full_path.clone(); - tmp_path.set_extension("tmp_aidx"); + tmp_path.set_extension("tmp_didx"); let file = std::fs::OpenOptions::new() .create(true).truncate(true) @@ -356,7 +356,7 @@ impl ArchiveIndexWriter { let mut writer = BufWriter::with_capacity(1024*1024, file); - let header_size = std::mem::size_of::(); + let header_size = std::mem::size_of::(); // todo: use static assertion when available in rust if header_size != 4096 { panic!("got unexpected header size"); } @@ -367,9 +367,9 @@ impl ArchiveIndexWriter { let uuid = Uuid::new_v4(); let mut buffer = vec![0u8; header_size]; - let header = crate::tools::map_struct_mut::(&mut buffer)?; + let header = crate::tools::map_struct_mut::(&mut buffer)?; - header.magic = *b"PROXMOX-AIDX"; + header.magic = *b"PROXMOX-DIDX"; header.version = u32::to_le(1); header.ctime = u64::to_le(ctime); header.uuid = *uuid.as_bytes(); @@ -446,7 +446,7 @@ impl ArchiveIndexWriter { } } -impl Write for ArchiveIndexWriter { +impl Write for DynamicIndexWriter { fn write(&mut self, data: &[u8]) -> std::result::Result {