mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-22 02:34:20 +01:00
image-cache: remove expect
This commit is contained in:
@@ -82,33 +82,37 @@ impl ImageCache {
|
|||||||
/// Migrate from base32 encoded url to sha256 url + sub-dir structure
|
/// Migrate from base32 encoded url to sha256 url + sub-dir structure
|
||||||
pub fn migrate_v0(&self) -> Result<()> {
|
pub fn migrate_v0(&self) -> Result<()> {
|
||||||
for file in std::fs::read_dir(&self.cache_dir)? {
|
for file in std::fs::read_dir(&self.cache_dir)? {
|
||||||
if let Ok(file) = file {
|
let file = if let Ok(f) = file {
|
||||||
if !file.path().is_file() {
|
f
|
||||||
continue;
|
} else {
|
||||||
}
|
// not sure how this could fail, skip entry
|
||||||
let old_filename = file.file_name().to_string_lossy().to_string();
|
continue;
|
||||||
let old_url = if let Some(u) =
|
};
|
||||||
base32::decode(base32::Alphabet::Crockford, &old_filename)
|
if !file.path().is_file() {
|
||||||
.and_then(|s| String::from_utf8(s).ok())
|
continue;
|
||||||
{
|
}
|
||||||
u
|
let old_filename = file.file_name().to_string_lossy().to_string();
|
||||||
} else {
|
let old_url = if let Some(u) =
|
||||||
warn!("Invalid base32 filename: {}", &old_filename);
|
base32::decode(base32::Alphabet::Crockford, &old_filename)
|
||||||
continue;
|
.and_then(|s| String::from_utf8(s).ok())
|
||||||
};
|
{
|
||||||
let new_path = self.cache_dir.join(Self::key(&old_url));
|
u
|
||||||
if let Some(p) = new_path.parent() {
|
} else {
|
||||||
create_dir_all(p)?;
|
warn!("Invalid base32 filename: {}", &old_filename);
|
||||||
}
|
continue;
|
||||||
|
};
|
||||||
|
let new_path = self.cache_dir.join(Self::key(&old_url));
|
||||||
|
if let Some(p) = new_path.parent() {
|
||||||
|
create_dir_all(p)?;
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(e) = std::fs::rename(file.path(), &new_path) {
|
if let Err(e) = std::fs::rename(file.path(), &new_path) {
|
||||||
warn!(
|
warn!(
|
||||||
"Failed to migrate file from {} to {}: {:?}",
|
"Failed to migrate file from {} to {}: {:?}",
|
||||||
file.path().display(),
|
file.path().display(),
|
||||||
new_path.display(),
|
new_path.display(),
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -208,7 +208,9 @@ impl Notedeck {
|
|||||||
let app_rect_handler = AppSizeHandler::new(&path);
|
let app_rect_handler = AppSizeHandler::new(&path);
|
||||||
|
|
||||||
// migrate
|
// migrate
|
||||||
img_cache.migrate_v0().expect("img-cache migration");
|
if let Err(e) = img_cache.migrate_v0() {
|
||||||
|
error!("error migrating image cache: {e}");
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
ndb,
|
ndb,
|
||||||
|
|||||||
Reference in New Issue
Block a user