backup/datastore.rs: use Arc for chunk_store references
This commit is contained in:
parent
1629d2ad7b
commit
150f1bd8f6
@ -21,8 +21,8 @@ pub struct ArchiveIndexHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct ArchiveIndexReader<'a> {
|
pub struct ArchiveIndexReader {
|
||||||
store: &'a ChunkStore,
|
store: Arc<ChunkStore>,
|
||||||
file: File,
|
file: File,
|
||||||
size: usize,
|
size: usize,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
@ -32,7 +32,7 @@ pub struct ArchiveIndexReader<'a> {
|
|||||||
ctime: u64,
|
ctime: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a> Drop for ArchiveIndexReader<'a> {
|
impl Drop for ArchiveIndexReader {
|
||||||
|
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Err(err) = self.unmap() {
|
if let Err(err) = self.unmap() {
|
||||||
@ -41,9 +41,9 @@ impl <'a> Drop for ArchiveIndexReader<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a> ArchiveIndexReader<'a> {
|
impl ArchiveIndexReader {
|
||||||
|
|
||||||
pub fn open(store: &'a ChunkStore, path: &Path) -> Result<Self, Error> {
|
pub fn open(store: Arc<ChunkStore>, path: &Path) -> Result<Self, Error> {
|
||||||
|
|
||||||
let full_path = store.relative_path(path);
|
let full_path = store.relative_path(path);
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ impl <'a> ArchiveIndexReader<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct BufferedArchiveReader<'a> {
|
pub struct BufferedArchiveReader<'a> {
|
||||||
index: &'a ArchiveIndexReader<'a>,
|
index: &'a ArchiveIndexReader,
|
||||||
archive_size: u64,
|
archive_size: u64,
|
||||||
read_buffer: Vec<u8>,
|
read_buffer: Vec<u8>,
|
||||||
buffered_chunk_idx: usize,
|
buffered_chunk_idx: usize,
|
||||||
|
@ -65,14 +65,14 @@ impl DataStore {
|
|||||||
|
|
||||||
pub fn create_image_writer<P: AsRef<Path>>(&self, filename: P, size: usize, chunk_size: usize) -> Result<ImageIndexWriter, Error> {
|
pub fn create_image_writer<P: AsRef<Path>>(&self, filename: P, size: usize, chunk_size: usize) -> Result<ImageIndexWriter, Error> {
|
||||||
|
|
||||||
let index = ImageIndexWriter::create(&self.chunk_store, filename.as_ref(), size, chunk_size)?;
|
let index = ImageIndexWriter::create(self.chunk_store.clone(), filename.as_ref(), size, chunk_size)?;
|
||||||
|
|
||||||
Ok(index)
|
Ok(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_image_reader<P: AsRef<Path>>(&self, filename: P) -> Result<ImageIndexReader, Error> {
|
pub fn open_image_reader<P: AsRef<Path>>(&self, filename: P) -> Result<ImageIndexReader, Error> {
|
||||||
|
|
||||||
let index = ImageIndexReader::open(&self.chunk_store, filename.as_ref())?;
|
let index = ImageIndexReader::open(self.chunk_store.clone(), filename.as_ref())?;
|
||||||
|
|
||||||
Ok(index)
|
Ok(index)
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ impl DataStore {
|
|||||||
|
|
||||||
pub fn open_archive_reader<P: AsRef<Path>>(&self, filename: P) -> Result<ArchiveIndexReader, Error> {
|
pub fn open_archive_reader<P: AsRef<Path>>(&self, filename: P) -> Result<ArchiveIndexReader, Error> {
|
||||||
|
|
||||||
let index = ArchiveIndexReader::open(&self.chunk_store, filename.as_ref())?;
|
let index = ArchiveIndexReader::open(self.chunk_store.clone(), filename.as_ref())?;
|
||||||
|
|
||||||
Ok(index)
|
Ok(index)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use failure::*;
|
|||||||
|
|
||||||
use super::chunk_store::*;
|
use super::chunk_store::*;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
@ -21,8 +22,8 @@ pub struct ImageIndexHeader {
|
|||||||
|
|
||||||
// split image into fixed size chunks
|
// split image into fixed size chunks
|
||||||
|
|
||||||
pub struct ImageIndexReader<'a> {
|
pub struct ImageIndexReader {
|
||||||
store: &'a ChunkStore,
|
store: Arc<ChunkStore>,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
chunk_size: usize,
|
chunk_size: usize,
|
||||||
size: usize,
|
size: usize,
|
||||||
@ -31,7 +32,7 @@ pub struct ImageIndexReader<'a> {
|
|||||||
ctime: u64,
|
ctime: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a> Drop for ImageIndexReader<'a> {
|
impl Drop for ImageIndexReader {
|
||||||
|
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Err(err) = self.unmap() {
|
if let Err(err) = self.unmap() {
|
||||||
@ -40,9 +41,9 @@ impl <'a> Drop for ImageIndexReader<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a> ImageIndexReader<'a> {
|
impl ImageIndexReader {
|
||||||
|
|
||||||
pub fn open(store: &'a ChunkStore, path: &Path) -> Result<Self, Error> {
|
pub fn open(store: Arc<ChunkStore>, path: &Path) -> Result<Self, Error> {
|
||||||
|
|
||||||
let full_path = store.relative_path(path);
|
let full_path = store.relative_path(path);
|
||||||
|
|
||||||
@ -150,8 +151,8 @@ impl <'a> ImageIndexReader<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ImageIndexWriter<'a> {
|
pub struct ImageIndexWriter {
|
||||||
store: &'a ChunkStore,
|
store: Arc<ChunkStore>,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
tmp_filename: PathBuf,
|
tmp_filename: PathBuf,
|
||||||
chunk_size: usize,
|
chunk_size: usize,
|
||||||
@ -162,7 +163,7 @@ pub struct ImageIndexWriter<'a> {
|
|||||||
ctime: u64,
|
ctime: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a> Drop for ImageIndexWriter<'a> {
|
impl Drop for ImageIndexWriter {
|
||||||
|
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let _ = std::fs::remove_file(&self.tmp_filename); // ignore errors
|
let _ = std::fs::remove_file(&self.tmp_filename); // ignore errors
|
||||||
@ -172,9 +173,9 @@ impl <'a> Drop for ImageIndexWriter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a> ImageIndexWriter<'a> {
|
impl ImageIndexWriter {
|
||||||
|
|
||||||
pub fn create(store: &'a ChunkStore, path: &Path, size: usize, chunk_size: usize) -> Result<Self, Error> {
|
pub fn create(store: Arc<ChunkStore>, path: &Path, size: usize, chunk_size: usize) -> Result<Self, Error> {
|
||||||
|
|
||||||
let full_path = store.relative_path(path);
|
let full_path = store.relative_path(path);
|
||||||
let mut tmp_path = full_path.clone();
|
let mut tmp_path = full_path.clone();
|
||||||
|
Loading…
Reference in New Issue
Block a user