Use relative links.

- In order to store the links in the inodes, we need to make sure
    that they are short.  The first step is to use relative links.
This commit is contained in:
Justus Winter 2019-02-22 15:45:34 +01:00
parent 0508342c31
commit 9e4926fcc9
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
3 changed files with 15 additions and 7 deletions

View File

@ -24,6 +24,7 @@ hex = "0.3"
lettre_email = "0.8"
handlebars = "1.1.0"
base64 = "0.10"
pathdiff = "0.1"
[dependencies.lettre]
version = "0.8"

View File

@ -7,6 +7,7 @@ use std::str;
use serde_json;
use tempfile;
use url;
use pathdiff::diff_paths;
use database::{Database, Delete, Verify};
use types::{Email, Fingerprint, KeyID};
@ -194,8 +195,9 @@ impl Database for Filesystem {
let email =
url::form_urlencoded::byte_serialize(email.to_string().as_bytes())
.collect::<String>();
let target = self.path_to_fingerprint(fpr);
let link = self.path_to_email(&email);
let target = diff_paths(&self.path_to_fingerprint(fpr),
link.parent().unwrap()).unwrap();
if link.exists() {
match link.symlink_metadata() {
@ -218,7 +220,8 @@ impl Database for Filesystem {
match read_link(link.clone()) {
Ok(target) => {
let expected = self.path_to_fingerprint(fpr);
let expected = diff_paths(&self.path_to_fingerprint(fpr),
link.parent().unwrap()).unwrap();
if target == expected {
remove_file(link)?;
@ -230,8 +233,9 @@ impl Database for Filesystem {
}
fn link_kid(&self, kid: &KeyID, fpr: &Fingerprint) -> Result<()> {
let target = self.path_to_fingerprint(fpr);
let link = self.path_to_keyid(kid);
let target = diff_paths(&self.path_to_fingerprint(fpr),
link.parent().unwrap()).unwrap();
if link.exists() {
match link.symlink_metadata() {
@ -263,12 +267,14 @@ impl Database for Filesystem {
}
fn link_fpr(&self, from: &Fingerprint, fpr: &Fingerprint) -> Result<()> {
let target = self.path_to_fingerprint(fpr);
let link = self.path_to_fingerprint(from);
if link == target {
if from == fpr {
return Ok(());
}
let link = self.path_to_fingerprint(from);
let target = diff_paths(&self.path_to_fingerprint(fpr),
link.parent().unwrap()).unwrap();
if link.exists() {
match link.symlink_metadata() {
Ok(ref meta) if meta.file_type().is_symlink() => {

View File

@ -29,6 +29,7 @@ extern crate parking_lot;
extern crate rand;
extern crate structopt;
extern crate tempfile;
extern crate pathdiff;
mod database;
mod mail;