Refactored common filename function.
This commit is contained in:
		@@ -117,6 +117,11 @@ impl MoreThanText {
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn filename(&self, id: &str) -> String {
 | 
			
		||||
        let filename = Path::new(&self.dir).join(&id);
 | 
			
		||||
        filename.into_os_string().into_string().unwrap()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn add_entry(&self, entry: CacheType) -> Result<String, DBError> {
 | 
			
		||||
        let mut id: String = "".to_string();
 | 
			
		||||
        let mut dup = true;
 | 
			
		||||
@@ -124,7 +129,7 @@ impl MoreThanText {
 | 
			
		||||
            id = thread_rng().sample_iter(&Alphanumeric).take(32).collect();
 | 
			
		||||
            dup = Path::new(&self.dir).join(&id).as_path().exists().await;
 | 
			
		||||
        }
 | 
			
		||||
        match write(Path::new(&self.dir).join(&id), entry.to_bytes()).await {
 | 
			
		||||
        match write(Path::new(&self.filename(&id)), entry.to_bytes()).await {
 | 
			
		||||
            Ok(_) => (),
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                let mut error = DBError::new("data write");
 | 
			
		||||
@@ -145,7 +150,7 @@ impl MoreThanText {
 | 
			
		||||
                entry.touch();
 | 
			
		||||
                Ok(entry.clone())
 | 
			
		||||
            }
 | 
			
		||||
            None => match read(Path::new(&self.dir).join(&id)).await {
 | 
			
		||||
            None => match read(Path::new(&self.filename(id))).await {
 | 
			
		||||
                Ok(content) => {
 | 
			
		||||
                    let data = CacheEntry::new(CacheType::from_bytes(content));
 | 
			
		||||
                    cache.insert(id.to_string(), data.clone());
 | 
			
		||||
@@ -161,7 +166,7 @@ impl MoreThanText {
 | 
			
		||||
            Ok(_) => (),
 | 
			
		||||
            Err(err) => return Err(err),
 | 
			
		||||
        }
 | 
			
		||||
        match write(Path::new(&self.dir).join(&id), entry.to_bytes()).await {
 | 
			
		||||
        match write(Path::new(&self.filename(id)), entry.to_bytes()).await {
 | 
			
		||||
            Ok(_) => (),
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                let mut error = DBError::new("data write");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user