fix invariant calculation/insertion
parent
c6283b5bc1
commit
0f006ea32c
|
@ -79,18 +79,23 @@ impl TryFrom<&InvariantEntry> for Entry {
|
|||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(invariant: &InvariantEntry) -> Result<Self, Self::Error> {
|
||||
let mut entity = Cursor::new(vec![0u8; 0]);
|
||||
entity.write_all(invariant.attribute.as_bytes())?;
|
||||
entity.write_all(invariant.value.to_string()?.as_bytes())?;
|
||||
|
||||
Ok(Entry {
|
||||
entity: Address::Hash(Hash(entity.into_inner())),
|
||||
entity: invariant.entity()?,
|
||||
attribute: invariant.attribute.clone(),
|
||||
value: invariant.value.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl InvariantEntry {
|
||||
pub fn entity(&self) -> Result<Address> {
|
||||
let mut entity = Cursor::new(vec![0u8; 0]);
|
||||
entity.write_all(self.attribute.as_bytes())?;
|
||||
entity.write_all(self.value.to_string()?.as_bytes())?;
|
||||
Ok(Address::Hash(hash(entity.into_inner())))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Entry {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} | {} | {}", self.entity, self.attribute, self.value)
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
use std::convert::TryFrom;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::{Instant, UNIX_EPOCH};
|
||||
use std::{fs, iter};
|
||||
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use chrono::prelude::*;
|
||||
use diesel::sqlite::Sqlite;
|
||||
use diesel::Connection;
|
||||
use log::{error, info, trace};
|
||||
use rayon::prelude::*;
|
||||
use serde_json::Value;
|
||||
use uuid::Uuid;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::addressing::Address;
|
||||
use crate::database::{
|
||||
bulk_retrieve_objects, file_set_valid, insert_entry, insert_file, query, retrieve_all_files,
|
||||
|
@ -8,20 +24,6 @@ use crate::hash::Hashable;
|
|||
use crate::jobs::{Job, JobContainer, JobId};
|
||||
use crate::models;
|
||||
use crate::models::File;
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use chrono::prelude::*;
|
||||
use diesel::sqlite::Sqlite;
|
||||
use diesel::Connection;
|
||||
use log::{error, info, trace};
|
||||
use rayon::prelude::*;
|
||||
use serde_json::Value;
|
||||
use std::convert::TryFrom;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::{Instant, UNIX_EPOCH};
|
||||
use std::{fs, iter};
|
||||
use uuid::Uuid;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
const DIR_TYPE: &str = "FS_DIR";
|
||||
const DIR_KEY: &str = "DIR";
|
||||
|
@ -31,7 +33,7 @@ lazy_static! {
|
|||
attribute: String::from(TYPE_ATTR),
|
||||
value: EntryValue::Value(Value::from(DIR_TYPE)),
|
||||
};
|
||||
static ref DIR_TYPE_ADDR: Address = DIR_TYPE_INVARIANT.address().unwrap();
|
||||
static ref DIR_TYPE_ADDR: Address = DIR_TYPE_INVARIANT.entity().unwrap();
|
||||
}
|
||||
|
||||
const FILE_TYPE: &str = "FS_FILE";
|
||||
|
@ -42,7 +44,7 @@ lazy_static! {
|
|||
attribute: String::from(TYPE_ATTR),
|
||||
value: EntryValue::Value(Value::from(FILE_TYPE)),
|
||||
};
|
||||
static ref FILE_TYPE_ADDR: Address = FILE_TYPE_INVARIANT.address().unwrap();
|
||||
static ref FILE_TYPE_ADDR: Address = FILE_TYPE_INVARIANT.entity().unwrap();
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -345,23 +347,23 @@ fn _rescan_vault<T: AsRef<Path>>(
|
|||
let start = Instant::now();
|
||||
|
||||
// Initialize types, etc...
|
||||
let file_type = insert_entry(&pool.get()?, Entry::try_from(&*FILE_TYPE_INVARIANT)?)?;
|
||||
insert_entry(&pool.get()?, Entry::try_from(&*FILE_TYPE_INVARIANT)?)?;
|
||||
for attr in &[FILE_IDENTITY_KEY, FILENAME_KEY] {
|
||||
insert_entry(
|
||||
&pool.get()?,
|
||||
Entry {
|
||||
entity: file_type.clone(),
|
||||
entity: FILE_TYPE_ADDR.clone(),
|
||||
attribute: String::from(TYPE_HAS_ATTR),
|
||||
value: EntryValue::Value(Value::from(*attr)),
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
||||
let dir_type = insert_entry(&pool.get()?, Entry::try_from(&*DIR_TYPE_INVARIANT)?)?;
|
||||
insert_entry(&pool.get()?, Entry::try_from(&*DIR_TYPE_INVARIANT)?)?;
|
||||
insert_entry(
|
||||
&pool.get()?,
|
||||
Entry {
|
||||
entity: dir_type,
|
||||
entity: DIR_TYPE_ADDR.clone(),
|
||||
attribute: String::from(TYPE_HAS_ATTR),
|
||||
value: EntryValue::Value(Value::from(DIR_KEY)),
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue