backup/chunk_store.rs: verify base path is absolute

This commit is contained in:
Dietmar Maurer 2019-01-20 16:49:22 +01:00
parent 059ca7c3a1
commit 68469eebb4
1 changed files with 10 additions and 0 deletions

View File

@ -82,6 +82,11 @@ impl ChunkStore {
pub fn create<P: Into<PathBuf>>(name: &str, path: P) -> Result<Self, Error> { pub fn create<P: Into<PathBuf>>(name: &str, path: P) -> Result<Self, Error> {
let base: PathBuf = path.into(); let base: PathBuf = path.into();
if !base.is_absolute() {
bail!("expected absolute path - got {:?}", base);
}
let chunk_dir = Self::chunk_dir(&base); let chunk_dir = Self::chunk_dir(&base);
if let Err(err) = std::fs::create_dir(&base) { if let Err(err) = std::fs::create_dir(&base) {
@ -114,6 +119,11 @@ impl ChunkStore {
pub fn open<P: Into<PathBuf>>(name: &str, path: P) -> Result<Self, Error> { pub fn open<P: Into<PathBuf>>(name: &str, path: P) -> Result<Self, Error> {
let base: PathBuf = path.into(); let base: PathBuf = path.into();
if !base.is_absolute() {
bail!("expected absolute path - got {:?}", base);
}
let chunk_dir = Self::chunk_dir(&base); let chunk_dir = Self::chunk_dir(&base);
if let Err(err) = std::fs::metadata(&chunk_dir) { if let Err(err) = std::fs::metadata(&chunk_dir) {