Remove pre_commit
This commit is contained in:
parent
16dc2917f0
commit
a8cd1d341d
@ -65,7 +65,6 @@ impl MusicHoard<NoDatabase, NoLibrary> {
|
||||
filter: CollectionFilter::default(),
|
||||
filtered: vec![],
|
||||
collection: vec![],
|
||||
pre_commit: vec![],
|
||||
database: NoDatabase,
|
||||
library: NoLibrary,
|
||||
library_cache: vec![],
|
||||
@ -87,7 +86,6 @@ impl<Library: ILibrary> MusicHoard<NoDatabase, Library> {
|
||||
filter: CollectionFilter::default(),
|
||||
filtered: vec![],
|
||||
collection: vec![],
|
||||
pre_commit: vec![],
|
||||
database: NoDatabase,
|
||||
library,
|
||||
library_cache: vec![],
|
||||
@ -109,7 +107,6 @@ impl<Database: IDatabase> MusicHoard<Database, NoLibrary> {
|
||||
filter: CollectionFilter::default(),
|
||||
filtered: vec![],
|
||||
collection: vec![],
|
||||
pre_commit: vec![],
|
||||
database,
|
||||
library: NoLibrary,
|
||||
library_cache: vec![],
|
||||
@ -131,7 +128,6 @@ impl<Database: IDatabase, Library: ILibrary> MusicHoard<Database, Library> {
|
||||
filter: CollectionFilter::default(),
|
||||
filtered: vec![],
|
||||
collection: vec![],
|
||||
pre_commit: vec![],
|
||||
database,
|
||||
library,
|
||||
library_cache: vec![],
|
||||
|
@ -122,8 +122,6 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
self.collection = self.merge_collections(database_cache);
|
||||
self.filtered = self.filter_collection();
|
||||
|
||||
self.pre_commit = self.collection.clone();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -365,7 +363,6 @@ pub trait IMusicHoardDatabasePrivate {
|
||||
|
||||
impl<Library> IMusicHoardDatabasePrivate for MusicHoard<NoDatabase, Library> {
|
||||
fn commit(&mut self) -> Result<(), Error> {
|
||||
self.collection = self.pre_commit.clone();
|
||||
self.filtered = self.filter_collection();
|
||||
Ok(())
|
||||
}
|
||||
@ -373,14 +370,11 @@ impl<Library> IMusicHoardDatabasePrivate for MusicHoard<NoDatabase, Library> {
|
||||
|
||||
impl<Database: IDatabase, Library> IMusicHoardDatabasePrivate for MusicHoard<Database, Library> {
|
||||
fn commit(&mut self) -> Result<(), Error> {
|
||||
if self.collection != self.pre_commit {
|
||||
if let Err(err) = self.database.save(&self.pre_commit) {
|
||||
self.pre_commit = self.collection.clone();
|
||||
if let Err(err) = self.database.save(&self.collection) {
|
||||
self.reload_database()?;
|
||||
return Err(err.into());
|
||||
}
|
||||
self.collection = self.pre_commit.clone();
|
||||
self.filtered = self.filter_collection();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -390,7 +384,7 @@ impl<Database: IDatabase, Library> MusicHoard<Database, Library> {
|
||||
where
|
||||
FnColl: FnOnce(&mut Collection),
|
||||
{
|
||||
fn_coll(&mut self.pre_commit);
|
||||
fn_coll(&mut self.collection);
|
||||
self.commit()
|
||||
}
|
||||
|
||||
@ -404,7 +398,7 @@ impl<Database: IDatabase, Library> MusicHoard<Database, Library> {
|
||||
FnArtist: FnOnce(&mut Artist),
|
||||
FnColl: FnOnce(&mut Collection),
|
||||
{
|
||||
let artist = Self::get_artist_mut_or_err(&mut self.pre_commit, artist_id)?;
|
||||
let artist = Self::get_artist_mut_or_err(&mut self.collection, artist_id)?;
|
||||
fn_artist(artist);
|
||||
self.update_collection(fn_coll)
|
||||
}
|
||||
@ -431,7 +425,7 @@ impl<Database: IDatabase, Library> MusicHoard<Database, Library> {
|
||||
FnAlbum: FnOnce(&mut Album),
|
||||
FnArtist: FnOnce(&mut Artist),
|
||||
{
|
||||
let artist = Self::get_artist_mut_or_err(&mut self.pre_commit, artist_id)?;
|
||||
let artist = Self::get_artist_mut_or_err(&mut self.collection, artist_id)?;
|
||||
let album = Self::get_album_mut_or_err(artist, album_id)?;
|
||||
fn_album(album);
|
||||
fn_artist(artist);
|
||||
@ -493,7 +487,7 @@ mod tests {
|
||||
.returning(|| Ok(FULL_COLLECTION.to_owned()));
|
||||
database
|
||||
.expect_save()
|
||||
.times(1)
|
||||
.times(3)
|
||||
.in_sequence(&mut seq)
|
||||
.with(predicate::eq(with_artist.clone()))
|
||||
.returning(|_| Ok(()));
|
||||
@ -789,7 +783,7 @@ mod tests {
|
||||
.returning(|| Ok(FULL_COLLECTION.to_owned()));
|
||||
database
|
||||
.expect_save()
|
||||
.times(1)
|
||||
.times(3)
|
||||
.in_sequence(&mut seq)
|
||||
.with(predicate::eq(with_album.clone()))
|
||||
.returning(|_| Ok(()));
|
||||
@ -1018,11 +1012,21 @@ mod tests {
|
||||
|
||||
let database_result = Err(database::SaveError::IoError(String::from("I/O error")));
|
||||
|
||||
database.expect_load().return_once(|| Ok(vec![]));
|
||||
let mut seq = Sequence::new();
|
||||
database
|
||||
.expect_load()
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.return_once(|| Ok(vec![]));
|
||||
database
|
||||
.expect_save()
|
||||
.times(1)
|
||||
.return_once(|_: &Collection| database_result);
|
||||
database
|
||||
.expect_load()
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.return_once(|| Ok(vec![]));
|
||||
|
||||
let mut music_hoard = MusicHoard::database(database);
|
||||
music_hoard.reload_database().unwrap();
|
||||
|
@ -23,7 +23,7 @@ pub trait IMusicHoardLibrary {
|
||||
|
||||
impl<Library: ILibrary> IMusicHoardLibrary for MusicHoard<NoDatabase, Library> {
|
||||
fn rescan_library(&mut self) -> Result<(), Error> {
|
||||
self.pre_commit = self.rescan_library_inner(vec![])?;
|
||||
self.collection = self.rescan_library_inner(vec![])?;
|
||||
self.commit()
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ impl<Database: IDatabase, Library: ILibrary> IMusicHoardLibrary for MusicHoard<D
|
||||
let mut database_cache = self.database.load()?;
|
||||
Self::sort_albums_and_tracks(database_cache.iter_mut());
|
||||
|
||||
self.pre_commit = self.rescan_library_inner(database_cache)?;
|
||||
self.collection = self.rescan_library_inner(database_cache)?;
|
||||
self.commit()
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ pub struct MusicHoard<Database, Library> {
|
||||
filter: CollectionFilter,
|
||||
filtered: Collection,
|
||||
collection: Collection,
|
||||
pre_commit: Collection,
|
||||
database: Database,
|
||||
library: Library,
|
||||
library_cache: Collection,
|
||||
|
Loading…
x
Reference in New Issue
Block a user