store file last modified date for each song

and add find-songs-with-changed-files to get api
This commit is contained in:
Mark
2024-08-26 20:16:01 +02:00
parent 1f39fe0cae
commit dd2cd8551d
4 changed files with 268 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ use std::{
collections::{BTreeSet, HashMap},
fs::{self, File},
io::{BufReader, Read, Write},
path::PathBuf,
path::{Path, PathBuf},
sync::{mpsc, Arc, Mutex},
time::{Duration, Instant},
};
@@ -73,7 +73,10 @@ impl Database {
self.client_is_init
}
pub fn get_path(&self, location: &DatabaseLocation) -> PathBuf {
self.lib_directory.join(&location.rel_path)
Self::get_path_nodb(&self.lib_directory, location)
}
pub fn get_path_nodb(lib_directory: &impl AsRef<Path>, location: &DatabaseLocation) -> PathBuf {
lib_directory.as_ref().join(&location.rel_path)
}
fn modified_data(&mut self) {
let now = Instant::now();

View File

@@ -21,6 +21,7 @@ use super::{
pub struct Song {
pub id: SongId,
pub location: DatabaseLocation,
pub file_last_modified_unix_timestamp: Option<u64>,
pub title: String,
pub album: Option<AlbumId>,
pub artist: ArtistId,
@@ -38,6 +39,7 @@ pub struct Song {
impl Song {
pub fn new(
location: DatabaseLocation,
file_last_modified_unix_timestamp: Option<u64>,
title: String,
album: Option<AlbumId>,
artist: ArtistId,
@@ -45,10 +47,12 @@ impl Song {
cover: Option<CoverId>,
file_size: u64,
duration_millis: u64,
general: GeneralData,
) -> Self {
Self {
id: 0,
location,
file_last_modified_unix_timestamp,
title,
album,
artist,
@@ -56,7 +60,7 @@ impl Song {
cover,
file_size,
duration_millis,
general: GeneralData::default(),
general,
cached_data: CachedData(Arc::new(Mutex::new((Err(None), None)))),
}
}
@@ -258,6 +262,7 @@ impl ToFromBytes for Song {
{
self.id.to_bytes(s)?;
self.location.to_bytes(s)?;
self.file_last_modified_unix_timestamp.to_bytes(s)?;
self.title.to_bytes(s)?;
self.album.to_bytes(s)?;
self.artist.to_bytes(s)?;
@@ -275,6 +280,7 @@ impl ToFromBytes for Song {
Ok(Self {
id: ToFromBytes::from_bytes(s)?,
location: ToFromBytes::from_bytes(s)?,
file_last_modified_unix_timestamp: ToFromBytes::from_bytes(s)?,
title: ToFromBytes::from_bytes(s)?,
album: ToFromBytes::from_bytes(s)?,
artist: ToFromBytes::from_bytes(s)?,