api3/admin/datastore/upload_catar.rs: implement upload future
This commit is contained in:
@ -3,6 +3,7 @@ use failure::*;
|
||||
use super::chunk_store::*;
|
||||
use super::chunker::*;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::io::{Read, Write, BufWriter};
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
@ -312,8 +313,8 @@ impl <'a> std::io::Seek for BufferedArchiveReader<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ArchiveIndexWriter<'a> {
|
||||
store: &'a ChunkStore,
|
||||
pub struct ArchiveIndexWriter {
|
||||
store: Arc<ChunkStore>,
|
||||
chunker: Chunker,
|
||||
writer: BufWriter<File>,
|
||||
closed: bool,
|
||||
@ -327,9 +328,16 @@ pub struct ArchiveIndexWriter<'a> {
|
||||
chunk_buffer: Vec<u8>,
|
||||
}
|
||||
|
||||
impl <'a> ArchiveIndexWriter<'a> {
|
||||
impl Drop for ArchiveIndexWriter {
|
||||
|
||||
pub fn create(store: &'a ChunkStore, path: &Path, chunk_size: usize) -> Result<Self, Error> {
|
||||
fn drop(&mut self) {
|
||||
let _ = std::fs::remove_file(&self.tmp_filename); // ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
impl ArchiveIndexWriter {
|
||||
|
||||
pub fn create(store: Arc<ChunkStore>, path: &Path, chunk_size: usize) -> Result<Self, Error> {
|
||||
|
||||
let full_path = store.relative_path(path);
|
||||
let mut tmp_path = full_path.clone();
|
||||
@ -433,7 +441,7 @@ impl <'a> ArchiveIndexWriter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl <'a> Write for ArchiveIndexWriter<'a> {
|
||||
impl Write for ArchiveIndexWriter {
|
||||
|
||||
fn write(&mut self, data: &[u8]) -> std::result::Result<usize, std::io::Error> {
|
||||
|
||||
|
@ -11,7 +11,7 @@ use super::image_index::*;
|
||||
use super::archive_index::*;
|
||||
|
||||
pub struct DataStore {
|
||||
chunk_store: ChunkStore,
|
||||
chunk_store: Arc<ChunkStore>,
|
||||
gc_mutex: Mutex<bool>,
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ impl DataStore {
|
||||
let chunk_store = ChunkStore::open(store_name, path)?;
|
||||
|
||||
Ok(Self {
|
||||
chunk_store: chunk_store,
|
||||
chunk_store: Arc::new(chunk_store),
|
||||
gc_mutex: Mutex::new(false),
|
||||
})
|
||||
}
|
||||
@ -82,11 +82,12 @@ impl DataStore {
|
||||
chunk_size: usize
|
||||
) -> Result<ArchiveIndexWriter, Error> {
|
||||
|
||||
let index = ArchiveIndexWriter::create(&self.chunk_store, filename.as_ref(), chunk_size)?;
|
||||
let index = ArchiveIndexWriter::create(
|
||||
self.chunk_store.clone(), filename.as_ref(), chunk_size)?;
|
||||
|
||||
Ok(index)
|
||||
}
|
||||
|
||||
|
||||
pub fn open_archive_reader<P: AsRef<Path>>(&self, filename: P) -> Result<ArchiveIndexReader, Error> {
|
||||
|
||||
let index = ArchiveIndexReader::open(&self.chunk_store, filename.as_ref())?;
|
||||
|
Reference in New Issue
Block a user