commit 23f0f78d8f05b87d7814c93795029765b925c107
Author: Christophe Fergeau <[email protected]>
Date: Thu Sep 30 18:46:08 2010 +0200
remove recent playcount file after db writing
Currently, when parsing an iPod database, libgpod reads the iPod
file containing information about the recent playcounts and merges
it with the database. However, it doesn't automatically remove this
file, and gives no way for applications to do it, as a result,
playcounts will be merged several times if itdb_parse is called
several time on an iPod. To avoid that, once the database has been
successfully written to disk, we make sure to remove the recent
playcount files.
src/itdb_itunesdb.c | 25 ++++++++++++++++++++++++-
1 files changed, 24 insertions(+), 1 deletions(-)
---
diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c
index bae2844..e9dc7cd 100644
--- a/src/itdb_itunesdb.c
+++ b/src/itdb_itunesdb.c
@@ -1198,6 +1198,26 @@ static gboolean playcounts_plist_read (FImport *fimp,
GValue *plist_data)
return TRUE;
}
+/* Delete the file containing the playcounts, once we saved the database,
+ * the recent playcounts will have been added to the database, so this
+ * file is no longer useful. */
+static void playcounts_reset (const char *mountpoint)
+{
+ const gchar *dirs[] = { "Play Counts", "iTunesStats",
+ "PlayCounts.plist", NULL };
+ const gchar **it;
+
+ for (it = dirs; *it != NULL; it++) {
+ char *playcounts_path;
+ const gchar *components[] = { *it, NULL };
+ playcounts_path = itdb_resolve_path (mountpoint, components);
+ if (playcounts_path != NULL) {
+ g_unlink (playcounts_path);
+ g_free (playcounts_path);
+ }
+ }
+}
+
/* Read the Play Count file (formed by adding "Play Counts" to the
* directory component of fimp->itdb->itdb_filename) and set up the
* GList *playcounts. If no Play Count file is present, attempt to
@@ -5972,8 +5992,11 @@ static gboolean itdb_write_file_internal (Itdb_iTunesDB
*itdb,
if (!fexp->error)
{
- if (!wcontents_write (cts))
+ if (wcontents_write (cts)) {
+ playcounts_reset (itdb_get_mountpoint (itdb));
+ } else {
g_propagate_error (&fexp->error, cts->error);
+ }
}
err:
if (fexp->error)
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2