You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.1 KiB
103 lines
2.1 KiB
use super::*;
|
|
use std::hash::{Hash, Hasher};
|
|
use std::borrow::Borrow;
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)] // Clone, PartialEq, Eq, Hash
|
|
pub struct Entry
|
|
{
|
|
name: String,
|
|
description: String,
|
|
|
|
/// The key used to encrypt the file, if any.
|
|
key: Option<aes::AesKey>,
|
|
|
|
/// The hash of the *unencrypted* data.
|
|
hash: sha256::Sha256Hash,
|
|
|
|
/// The tags for this entry.
|
|
///
|
|
/// # Note
|
|
/// This should be updated the same as the `Store`'s `tags` and `tag_mappings`. The duplication here is for lookup convenience / caching.
|
|
pub(super) tags: Vec<String>,
|
|
|
|
/// The *original* filename of the item, *not* the path to the real file for this item (see `location`).
|
|
filename: OsString,
|
|
|
|
/// Filename *relative* to the root of the store
|
|
location: PathBuf,
|
|
|
|
/// The state of caching this entry is currently in. This should not be saved as it has no meaning regarding the actual data itself.
|
|
#[serde(skip)]
|
|
cache: DataCacheState,
|
|
}
|
|
|
|
impl Entry
|
|
{
|
|
/// The sha256 hash of the data in this entry
|
|
pub fn hash(&self) -> &sha256::Sha256Hash
|
|
{
|
|
&self.hash
|
|
}
|
|
}
|
|
|
|
impl Entry
|
|
{
|
|
/// Consume and drop the cache. Only that useful as shim for mapping.
|
|
#[inline(always)] pub(super) fn with_no_cache(self) -> Self
|
|
{
|
|
Self {
|
|
cache: Default::default(),
|
|
..self
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Borrow<sha256::Sha256Hash> for Entry
|
|
{
|
|
#[inline] fn borrow(&self) -> &sha256::Sha256Hash
|
|
{
|
|
&self.hash
|
|
}
|
|
}
|
|
|
|
|
|
impl Hash for Entry {
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
self.hash.hash(state)
|
|
}
|
|
}
|
|
|
|
impl PartialEq for Entry
|
|
{
|
|
fn eq(&self, other: &Self) -> bool
|
|
{
|
|
macro_rules! eq {
|
|
($one:ident) => (self.$one == other.$one);
|
|
($($many:ident),*) => {
|
|
$(
|
|
eq!($many)
|
|
)&& *
|
|
};
|
|
}
|
|
|
|
eq!(name, description, key, tags, filename, location)
|
|
}
|
|
}
|
|
impl Eq for Entry{}
|
|
|
|
impl Clone for Entry
|
|
{
|
|
fn clone(&self) -> Self {
|
|
macro_rules! clone {
|
|
($($many:ident),*) => {
|
|
Self {
|
|
cache: Default::default(),
|
|
$($many: self.$many.clone()),*
|
|
}
|
|
}
|
|
}
|
|
clone!(name, description, key, tags, filename, location, hash)
|
|
}
|
|
}
|