Revert "Code fix"
This reverts commit ce3571e393eeb869acdf541a1099d39524e286c1.
This commit is contained in:
parent
ce3571e393
commit
e64dac6798
@ -13,8 +13,8 @@ pub trait IDatabase {
|
||||
/// Load collection from the database.
|
||||
fn load(&self) -> Result<Collection, LoadError>;
|
||||
|
||||
/// Save collection to the database. Return the written data.
|
||||
fn save(&mut self, collection: &Collection) -> Result<Collection, SaveError>;
|
||||
/// Save collection to the database.
|
||||
fn save(&mut self, collection: &Collection) -> Result<(), SaveError>;
|
||||
}
|
||||
|
||||
/// Null database implementation of [`IDatabase`].
|
||||
@ -25,8 +25,8 @@ impl IDatabase for NullDatabase {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
fn save(&mut self, _collection: &Collection) -> Result<Collection, SaveError> {
|
||||
Ok(vec![])
|
||||
fn save(&mut self, _collection: &Collection) -> Result<(), SaveError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,15 +374,10 @@ 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 {
|
||||
match self.database.save(&self.pre_commit) {
|
||||
Ok(collection) => {
|
||||
self.database_cache = collection;
|
||||
}
|
||||
Err(err) => {
|
||||
if let Err(err) = self.database.save(&self.pre_commit) {
|
||||
self.pre_commit = self.collection.clone();
|
||||
return Err(err.into());
|
||||
}
|
||||
}
|
||||
self.collection = self.pre_commit.clone();
|
||||
self.filtered = self.filter_collection();
|
||||
}
|
||||
@ -501,13 +496,13 @@ mod tests {
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.with(predicate::eq(with_artist.clone()))
|
||||
.returning(|_| Ok(vec![]));
|
||||
.returning(|_| Ok(()));
|
||||
database
|
||||
.expect_save()
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.with(predicate::eq(collection.clone()))
|
||||
.returning(|_| Ok(vec![]));
|
||||
.returning(|_| Ok(()));
|
||||
|
||||
let mut music_hoard = MusicHoard::database(database).unwrap();
|
||||
assert_eq!(music_hoard.collection, collection);
|
||||
@ -529,7 +524,7 @@ mod tests {
|
||||
fn artist_sort_set_clear() {
|
||||
let mut database = MockIDatabase::new();
|
||||
database.expect_load().times(1).returning(|| Ok(vec![]));
|
||||
database.expect_save().times(4).returning(|_| Ok(vec![]));
|
||||
database.expect_save().times(4).returning(|_| Ok(()));
|
||||
|
||||
type MH = MusicHoard<MockIDatabase, NoLibrary>;
|
||||
let mut music_hoard: MH = MusicHoard::database(database).unwrap();
|
||||
@ -597,7 +592,7 @@ mod tests {
|
||||
fn set_clear_artist_mb_ref() {
|
||||
let mut database = MockIDatabase::new();
|
||||
database.expect_load().times(1).returning(|| Ok(vec![]));
|
||||
database.expect_save().times(3).returning(|_| Ok(vec![]));
|
||||
database.expect_save().times(3).returning(|_| Ok(()));
|
||||
|
||||
let mut artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
@ -643,7 +638,7 @@ mod tests {
|
||||
fn set_clear_artist_info() {
|
||||
let mut database = MockIDatabase::new();
|
||||
database.expect_load().times(1).returning(|| Ok(vec![]));
|
||||
database.expect_save().times(3).returning(|_| Ok(vec![]));
|
||||
database.expect_save().times(3).returning(|_| Ok(()));
|
||||
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
@ -687,7 +682,7 @@ mod tests {
|
||||
fn add_to_remove_from_property() {
|
||||
let mut database = MockIDatabase::new();
|
||||
database.expect_load().times(1).returning(|| Ok(vec![]));
|
||||
database.expect_save().times(3).returning(|_| Ok(vec![]));
|
||||
database.expect_save().times(3).returning(|_| Ok(()));
|
||||
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
@ -736,7 +731,7 @@ mod tests {
|
||||
fn set_clear_property() {
|
||||
let mut database = MockIDatabase::new();
|
||||
database.expect_load().times(1).returning(|| Ok(vec![]));
|
||||
database.expect_save().times(3).returning(|_| Ok(vec![]));
|
||||
database.expect_save().times(3).returning(|_| Ok(()));
|
||||
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
@ -802,13 +797,13 @@ mod tests {
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.with(predicate::eq(with_album.clone()))
|
||||
.returning(|_| Ok(vec![]));
|
||||
.returning(|_| Ok(()));
|
||||
database
|
||||
.expect_save()
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.with(predicate::eq(collection.clone()))
|
||||
.returning(|_| Ok(vec![]));
|
||||
.returning(|_| Ok(()));
|
||||
|
||||
let mut music_hoard = MusicHoard::database(database).unwrap();
|
||||
assert_eq!(music_hoard.collection, collection);
|
||||
@ -847,7 +842,7 @@ mod tests {
|
||||
.expect_load()
|
||||
.times(1)
|
||||
.return_once(|| Ok(database_result));
|
||||
database.expect_save().times(2).returning(|_| Ok(vec![]));
|
||||
database.expect_save().times(2).returning(|_| Ok(()));
|
||||
|
||||
let mut music_hoard = MusicHoard::database(database).unwrap();
|
||||
let album = &music_hoard.collection[0].albums[0];
|
||||
@ -905,7 +900,7 @@ mod tests {
|
||||
.expect_load()
|
||||
.times(1)
|
||||
.return_once(|| Ok(database_result));
|
||||
database.expect_save().times(2).returning(|_| Ok(vec![]));
|
||||
database.expect_save().times(2).returning(|_| Ok(()));
|
||||
|
||||
let mut music_hoard = MusicHoard::database(database).unwrap();
|
||||
assert_eq!(music_hoard.collection[0].albums[0].meta.seq, AlbumSeq(0));
|
||||
@ -945,7 +940,7 @@ mod tests {
|
||||
.expect_load()
|
||||
.times(1)
|
||||
.return_once(|| Ok(database_result));
|
||||
database.expect_save().times(2).returning(|_| Ok(vec![]));
|
||||
database.expect_save().times(2).returning(|_| Ok(()));
|
||||
let mut music_hoard = MusicHoard::database(database).unwrap();
|
||||
|
||||
let meta = &music_hoard.collection[0].albums[0].meta;
|
||||
|
@ -157,7 +157,7 @@ mod tests {
|
||||
.expect_save()
|
||||
.with(predicate::eq(&*LIBRARY_COLLECTION))
|
||||
.times(1)
|
||||
.return_once(|_| Ok(vec![]));
|
||||
.return_once(|_| Ok(()));
|
||||
|
||||
let mut music_hoard = MusicHoard::new(database, library).unwrap();
|
||||
|
||||
|
@ -55,12 +55,11 @@ impl<JDB: IJsonDatabaseBackend> IDatabase for JsonDatabase<JDB> {
|
||||
Ok(database.into())
|
||||
}
|
||||
|
||||
fn save(&mut self, collection: &Collection) -> Result<Collection, SaveError> {
|
||||
fn save(&mut self, collection: &Collection) -> Result<(), SaveError> {
|
||||
let database: SerializeDatabase = collection.into();
|
||||
let serialized = serde_json::to_string(&database)?;
|
||||
let deserialized: DeserializeDatabase = serde_json::from_str(&serialized)?;
|
||||
self.backend.write(&serialized)?;
|
||||
Ok(deserialized.into())
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user