summaryrefslogtreecommitdiff
path: root/src/database.rs
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2020-05-25 19:07:31 -0400
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2020-05-25 19:07:31 -0400
commit63ca9b9bde494f4857589b9dea03d93f981c5d45 (patch)
treefe384847c495bc9be0d2f428731062c39dcd4e25 /src/database.rs
parent899f517859fe2d2981ec5214892c1af966358c6a (diff)
Implement `put_posts`.
Diffstat (limited to 'src/database.rs')
-rw-r--r--src/database.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/database.rs b/src/database.rs
index 7b69a21..db33117 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -16,7 +16,9 @@
// License along with бирка-тян. If not, see <http://www.gnu.org/licenses/>.
use anyhow::Result;
+use blake2::{Blake2b, Digest};
use rusqlite::{params, Connection};
+use std::io;
use std::path::Path;
/// A connection to бирка-тян's tag database.
@@ -185,8 +187,8 @@ impl TagDatabase {
let (n, id) = pair;
format!(
"INNER JOIN mapping as m{n}
- ON images.id = m{n}.image
- AND {id} = m{n}.tag",
+ ON images.id = m{n}.image
+ AND {id} = m{n}.tag",
n = n,
id = id
)
@@ -263,6 +265,14 @@ pub struct Image {
pub orig_dir: String,
}
+/// Return a base64-encoded BLAKE2b hash identifying the file at `path`.
+pub fn hash_file(path: &Path) -> Result<String> {
+ let mut file = std::fs::File::open(path)?;
+ let mut hasher = Blake2b::new();
+ io::copy(&mut file, &mut hasher)?;
+ Ok(base64::encode(&hasher.result()))
+}
+
#[cfg(test)]
mod tests {
use super::*;