Skip to content
Snippets Groups Projects
Unverified Commit 2385bd1c authored by hamidreza kalbasi's avatar hamidreza kalbasi Committed by Timo Kösters
Browse files

add migrations

parent affa1248
No related branches found
No related tags found
No related merge requests found
...@@ -20,11 +20,7 @@ ...@@ -20,11 +20,7 @@
use rocket::futures::{channel::mpsc, stream::FuturesUnordered, StreamExt}; use rocket::futures::{channel::mpsc, stream::FuturesUnordered, StreamExt};
use ruma::{DeviceId, ServerName, UserId}; use ruma::{DeviceId, ServerName, UserId};
use serde::Deserialize; use serde::Deserialize;
use std::{ use std::{collections::HashMap, fs::{self, remove_dir_all}, io::Write, sync::{Arc, RwLock}};
collections::HashMap,
fs::remove_dir_all,
sync::{Arc, RwLock},
};
use tokio::sync::Semaphore; use tokio::sync::Semaphore;
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
...@@ -253,9 +249,11 @@ pub async fn load_or_create(config: Config) -> Result<Arc<Self>> { ...@@ -253,9 +249,11 @@ pub async fn load_or_create(config: Config) -> Result<Arc<Self>> {
for (userid, password) in db.users.userid_password.iter() { for (userid, password) in db.users.userid_password.iter() {
let password = utils::string_from_bytes(&password); let password = utils::string_from_bytes(&password);
if password.map_or(false, |password| { let empty_hashed_password = password.map_or(false, |password| {
argon2::verify_encoded(&password, b"").unwrap_or(false) argon2::verify_encoded(&password, b"").unwrap_or(false)
}) { });
if empty_hashed_password {
db.users.userid_password.insert(&userid, b"")?; db.users.userid_password.insert(&userid, b"")?;
} }
} }
...@@ -265,6 +263,23 @@ pub async fn load_or_create(config: Config) -> Result<Arc<Self>> { ...@@ -265,6 +263,23 @@ pub async fn load_or_create(config: Config) -> Result<Arc<Self>> {
println!("Migration: 1 -> 2 finished"); println!("Migration: 1 -> 2 finished");
} }
if db.globals.database_version()? < 3 {
// Move media to filesystem
for (key, content) in db.media.mediaid_file.iter() {
if content.len() == 0 {
continue;
}
let path = db.globals.get_media_file(&key);
let mut file = fs::File::create(path)?;
file.write_all(&content)?;
db.media.mediaid_file.insert(&key, &[])?;
}
db.globals.bump_database_version(3)?;
println!("Migration: 2 -> 3 finished");
}
// This data is probably outdated // This data is probably outdated
db.rooms.edus.presenceid_presence.clear()?; db.rooms.edus.presenceid_presence.clear()?;
......
...@@ -103,7 +103,7 @@ pub async fn get(&self, globals: &Globals, mxc: &str) -> Result<Option<FileMeta> ...@@ -103,7 +103,7 @@ pub async fn get(&self, globals: &Globals, mxc: &str) -> Result<Option<FileMeta>
let mut iter = self.mediaid_file.scan_prefix(prefix); let mut iter = self.mediaid_file.scan_prefix(prefix);
if let Some((key, _)) = iter.next() { if let Some((key, _)) = iter.next() {
let path = globals.get_media_file(&key); let path = globals.get_media_file(&key);
let mut file = vec![]; let mut file = Vec::new();
File::open(path).await?.read_to_end(&mut file).await?; File::open(path).await?.read_to_end(&mut file).await?;
let mut parts = key.rsplit(|&b| b == 0xff); let mut parts = key.rsplit(|&b| b == 0xff);
...@@ -192,7 +192,7 @@ pub async fn get_thumbnail( ...@@ -192,7 +192,7 @@ pub async fn get_thumbnail(
if let Some((key, _)) = self.mediaid_file.scan_prefix(thumbnail_prefix).next() { if let Some((key, _)) = self.mediaid_file.scan_prefix(thumbnail_prefix).next() {
// Using saved thumbnail // Using saved thumbnail
let path = globals.get_media_file(&key); let path = globals.get_media_file(&key);
let mut file = vec![]; let mut file = Vec::new();
File::open(path).await?.read_to_end(&mut file).await?; File::open(path).await?.read_to_end(&mut file).await?;
let mut parts = key.rsplit(|&b| b == 0xff); let mut parts = key.rsplit(|&b| b == 0xff);
...@@ -227,7 +227,7 @@ pub async fn get_thumbnail( ...@@ -227,7 +227,7 @@ pub async fn get_thumbnail(
} else if let Some((key, _)) = self.mediaid_file.scan_prefix(original_prefix).next() { } else if let Some((key, _)) = self.mediaid_file.scan_prefix(original_prefix).next() {
// Generate a thumbnail // Generate a thumbnail
let path = globals.get_media_file(&key); let path = globals.get_media_file(&key);
let mut file = vec![]; let mut file = Vec::new();
File::open(path).await?.read_to_end(&mut file).await?; File::open(path).await?.read_to_end(&mut file).await?;
let mut parts = key.rsplit(|&b| b == 0xff); let mut parts = key.rsplit(|&b| b == 0xff);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment