Merge pull request #242 from matthiasbeyer/libimagstore/revert-id_in_store-check
Revert "Check whether the StoreId is inside the store, before doing a…
This commit is contained in:
commit
9a918c9252
3 changed files with 15 additions and 29 deletions
|
@ -19,7 +19,6 @@ pub enum StoreErrorKind {
|
||||||
IoError,
|
IoError,
|
||||||
StorePathExists,
|
StorePathExists,
|
||||||
StorePathCreate,
|
StorePathCreate,
|
||||||
StorePathOutsideStore,
|
|
||||||
LockPoisoned,
|
LockPoisoned,
|
||||||
EntryAlreadyBorrowed,
|
EntryAlreadyBorrowed,
|
||||||
EntryAlreadyExists,
|
EntryAlreadyExists,
|
||||||
|
@ -42,7 +41,6 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
|
||||||
&StoreErrorKind::IoError => "File Error",
|
&StoreErrorKind::IoError => "File Error",
|
||||||
&StoreErrorKind::StorePathExists => "Store path exists",
|
&StoreErrorKind::StorePathExists => "Store path exists",
|
||||||
&StoreErrorKind::StorePathCreate => "Store path create",
|
&StoreErrorKind::StorePathCreate => "Store path create",
|
||||||
&StoreErrorKind::StorePathOutsideStore => "Store path would be outside of store",
|
|
||||||
&StoreErrorKind::LockPoisoned
|
&StoreErrorKind::LockPoisoned
|
||||||
=> "The internal Store Lock has been poisoned",
|
=> "The internal Store Lock has been poisoned",
|
||||||
&StoreErrorKind::EntryAlreadyBorrowed => "Entry is already borrowed",
|
&StoreErrorKind::EntryAlreadyBorrowed => "Entry is already borrowed",
|
||||||
|
|
|
@ -129,13 +129,17 @@ impl Store {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates the Entry at the given location (inside the entry)
|
fn storify_id(&self, id: StoreId) -> StoreId {
|
||||||
pub fn create<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
|
debug!("Create new store id out of: {:?} and {:?}", self.location, id);
|
||||||
if !self.id_in_store(&id) {
|
let mut new_id = self.location.clone();
|
||||||
debug!("'{:?}' seems not to be in '{:?}'", id, self.location);
|
new_id.push(id);
|
||||||
return Err(StoreError::new(StoreErrorKind::StorePathOutsideStore, None));
|
debug!("Created: '{:?}'", new_id);
|
||||||
|
new_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates the Entry at the given location (inside the entry)
|
||||||
|
pub fn create<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
|
||||||
|
let id = self.storify_id(id);
|
||||||
let hsmap = self.entries.write();
|
let hsmap = self.entries.write();
|
||||||
if hsmap.is_err() {
|
if hsmap.is_err() {
|
||||||
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
|
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
|
||||||
|
@ -155,11 +159,7 @@ impl Store {
|
||||||
/// Borrow a given Entry. When the `FileLockEntry` is either `update`d or
|
/// Borrow a given Entry. When the `FileLockEntry` is either `update`d or
|
||||||
/// dropped, the new Entry is written to disk
|
/// dropped, the new Entry is written to disk
|
||||||
pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
|
pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
|
||||||
if !self.id_in_store(&id) {
|
let id = self.storify_id(id);
|
||||||
debug!("'{:?}' seems not to be in '{:?}'", id, self.location);
|
|
||||||
return Err(StoreError::new(StoreErrorKind::StorePathOutsideStore, None));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.entries
|
self.entries
|
||||||
.write()
|
.write()
|
||||||
.map_err(|_| StoreError::new(StoreErrorKind::LockPoisoned, None))
|
.map_err(|_| StoreError::new(StoreErrorKind::LockPoisoned, None))
|
||||||
|
@ -211,6 +211,7 @@ impl Store {
|
||||||
/// Retrieve a copy of a given entry, this cannot be used to mutate
|
/// Retrieve a copy of a given entry, this cannot be used to mutate
|
||||||
/// the one on disk
|
/// the one on disk
|
||||||
pub fn retrieve_copy(&self, id: StoreId) -> Result<Entry> {
|
pub fn retrieve_copy(&self, id: StoreId) -> Result<Entry> {
|
||||||
|
let id = self.storify_id(id);
|
||||||
let entries_lock = self.entries.write();
|
let entries_lock = self.entries.write();
|
||||||
if entries_lock.is_err() {
|
if entries_lock.is_err() {
|
||||||
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
|
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
|
||||||
|
@ -228,11 +229,7 @@ impl Store {
|
||||||
|
|
||||||
/// Delete an entry
|
/// Delete an entry
|
||||||
pub fn delete(&self, id: StoreId) -> Result<()> {
|
pub fn delete(&self, id: StoreId) -> Result<()> {
|
||||||
if !self.id_in_store(&id) {
|
let id = self.storify_id(id);
|
||||||
debug!("'{:?}' seems not to be in '{:?}'", id, self.location);
|
|
||||||
return Err(StoreError::new(StoreErrorKind::StorePathOutsideStore, None));
|
|
||||||
}
|
|
||||||
|
|
||||||
let entries_lock = self.entries.write();
|
let entries_lock = self.entries.write();
|
||||||
if entries_lock.is_err() {
|
if entries_lock.is_err() {
|
||||||
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
|
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
|
||||||
|
@ -250,19 +247,11 @@ impl Store {
|
||||||
remove_file(&id).map_err(|e| StoreError::new(StoreErrorKind::FileError, Some(Box::new(e))))
|
remove_file(&id).map_err(|e| StoreError::new(StoreErrorKind::FileError, Some(Box::new(e))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id_in_store(&self, path: &StoreId) -> bool {
|
|
||||||
path.canonicalize()
|
|
||||||
.map(|can| {
|
|
||||||
can.starts_with(&self.location)
|
|
||||||
})
|
|
||||||
.unwrap_or(path.starts_with(&self.location))
|
|
||||||
// we return false, as fs::canonicalize() returns an Err(..) on filesystem errors
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the path where this store is on the disk
|
/// Gets the path where this store is on the disk
|
||||||
pub fn path(&self) -> &PathBuf {
|
pub fn path(&self) -> &PathBuf {
|
||||||
&self.location
|
&self.location
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Store {
|
impl Drop for Store {
|
||||||
|
|
|
@ -44,7 +44,7 @@ macro_rules! module_entry_path_mod {
|
||||||
/// Path has to be a valid UTF-8 string or this will panic!
|
/// Path has to be a valid UTF-8 string or this will panic!
|
||||||
pub fn new<P: AsRef<Path>>(pa: P) -> ModuleEntryPath {
|
pub fn new<P: AsRef<Path>>(pa: P) -> ModuleEntryPath {
|
||||||
let mut path = PathBuf::new();
|
let mut path = PathBuf::new();
|
||||||
path.push(format!("/{}", $name));
|
path.push(format!("{}", $name));
|
||||||
path.push(pa.as_ref().clone());
|
path.push(pa.as_ref().clone());
|
||||||
let version = Version::parse($version).unwrap();
|
let version = Version::parse($version).unwrap();
|
||||||
let name = pa.as_ref().file_name().unwrap()
|
let name = pa.as_ref().file_name().unwrap()
|
||||||
|
@ -99,8 +99,7 @@ mod test {
|
||||||
fn correct_path() {
|
fn correct_path() {
|
||||||
let p = module_path::ModuleEntryPath::new("test");
|
let p = module_path::ModuleEntryPath::new("test");
|
||||||
|
|
||||||
assert_eq!(p.into_storeid().to_str().unwrap(),
|
assert_eq!(p.into_storeid().to_str().unwrap(), "test/test~0.2.0-alpha+leet1337");
|
||||||
"/test/test~0.2.0-alpha+leet1337");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue