[banshee] Dispose TagLib.File
- From: Alexander Kojevnikov <alexk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] Dispose TagLib.File
- Date: Sun, 21 Mar 2010 00:14:50 +0000 (UTC)
commit 215a95fb78deb6162e0d4d350a1ecd72ff867fc6
Author: Alexander Kojevnikov <alexander kojevnikov com>
Date: Sun Mar 21 11:12:48 2010 +1100
Dispose TagLib.File
build/m4/banshee/taglib.m4 | 2 +-
.../Banshee.Collection/FileTrackInfo.cs | 24 ++++++++++----------
.../Banshee.Core/Banshee.Streaming/StreamTagger.cs | 12 +++++-----
.../DatabaseImportManager.cs | 4 ++-
.../Banshee.Collection/RescanPipeline.cs | 5 ++-
.../Banshee.Database/BansheeDbFormatMigrator.cs | 5 ++-
.../Banshee.Metadata.Embedded/EmbeddedQueryJob.cs | 9 +-----
.../Banshee.Metadata/Tests/TaglibReadWriteTests.cs | 2 +
.../Banshee.Streaming/RadioTrackInfo.cs | 5 ++-
.../Banshee.AudioCd/AudioCdRipper.cs | 4 ++-
.../Banshee.LibraryWatcher/SourceWatcher.cs | 9 +++++--
.../Banshee.Podcasting.Data/PodcastTrackInfo.cs | 5 ++-
12 files changed, 47 insertions(+), 39 deletions(-)
---
diff --git a/build/m4/banshee/taglib.m4 b/build/m4/banshee/taglib.m4
index cfeb328..1fde144 100644
--- a/build/m4/banshee/taglib.m4
+++ b/build/m4/banshee/taglib.m4
@@ -1,5 +1,5 @@
AC_DEFUN([BANSHEE_CHECK_TAGLIB_SHARP],
[
- PKG_CHECK_MODULES(TAGLIB_SHARP, taglib-sharp >= 2.0.3.5)
+ PKG_CHECK_MODULES(TAGLIB_SHARP, taglib-sharp >= 2.0.3.7)
AC_SUBST(TAGLIB_SHARP_LIBS)
])
diff --git a/src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs b/src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs
index 4399eac..275c4aa 100644
--- a/src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs
+++ b/src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs
@@ -43,22 +43,22 @@ namespace Banshee.Collection
LoadFromUri(uri);
Uri = uri;
}
-
+
private void LoadFromUri (SafeUri uri)
{
ParsePath (uri.LocalPath);
- TagLib.File file = Banshee.IO.DemuxVfs.OpenFile (uri.LocalPath);
-
- ArtistName = Choose (file.Tag.JoinedAlbumArtists, ArtistName);
- AlbumTitle = Choose (file.Tag.Album, AlbumTitle);
- TrackTitle = Choose (file.Tag.Title, TrackTitle);
- Genre = Choose (file.Tag.FirstGenre, Genre);
- DiscNumber = file.Tag.Disc == 0 ? (int)DiscNumber : (int)file.Tag.Disc;
- TrackNumber = file.Tag.Track == 0 ? (int)TrackNumber : (int)file.Tag.Track;
- TrackCount = file.Tag.TrackCount == 0 ? (int)TrackCount : (int)file.Tag.TrackCount;
- Duration = file.Properties.Duration;
- Year = (int)file.Tag.Year;
+ using (var file = Banshee.IO.DemuxVfs.OpenFile (uri.LocalPath)) {
+ ArtistName = Choose (file.Tag.JoinedAlbumArtists, ArtistName);
+ AlbumTitle = Choose (file.Tag.Album, AlbumTitle);
+ TrackTitle = Choose (file.Tag.Title, TrackTitle);
+ Genre = Choose (file.Tag.FirstGenre, Genre);
+ DiscNumber = file.Tag.Disc == 0 ? (int)DiscNumber : (int)file.Tag.Disc;
+ TrackNumber = file.Tag.Track == 0 ? (int)TrackNumber : (int)file.Tag.Track;
+ TrackCount = file.Tag.TrackCount == 0 ? (int)TrackCount : (int)file.Tag.TrackCount;
+ Duration = file.Properties.Duration;
+ Year = (int)file.Tag.Year;
+ }
DateAdded = DateTime.Now;
}
diff --git a/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs b/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs
index 6338afe..90a41fb 100644
--- a/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs
+++ b/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs
@@ -124,11 +124,12 @@ namespace Banshee.Streaming
public static void TrackInfoMerge (TrackInfo track, SafeUri uri)
{
track.Uri = uri;
- TagLib.File file = StreamTagger.ProcessUri (uri);
- TrackInfoMerge (track, file);
+ using (var file = StreamTagger.ProcessUri (uri)) {
+ TrackInfoMerge (track, file);
- if (file == null) {
- track.TrackTitle = uri.AbsoluteUri;
+ if (file == null) {
+ track.TrackTitle = uri.AbsoluteUri;
+ }
}
}
@@ -189,7 +190,6 @@ namespace Banshee.Streaming
track.Rating = Choose (file_rating, track.Rating, preferTrackInfo);
track.PlayCount = Choose (file_playcount, track.PlayCount, preferTrackInfo);
}
- file.Mode = TagLib.File.AccessMode.Closed;
} else {
track.MediaAttributes = TrackMediaAttributes.AudioStream;
if (track.Uri != null && VideoExtensions.IsMatchingFile (track.Uri.AbsoluteUri)) {
@@ -322,7 +322,7 @@ namespace Banshee.Streaming
}
file.Save ();
- file.Mode = TagLib.File.AccessMode.Closed;
+ file.Dispose ();
track.FileSize = Banshee.IO.File.GetSize (track.Uri);
track.FileModifiedStamp = Banshee.IO.File.GetModifiedTime (track.Uri);
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
index 7d04bae..618da0d 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
@@ -176,7 +176,9 @@ namespace Banshee.Collection.Database
try {
track = new DatabaseTrackInfo ();
track.Uri = uri;
- StreamTagger.TrackInfoMerge (track, StreamTagger.ProcessUri (uri), false, true);
+ using (var file = StreamTagger.ProcessUri (uri)) {
+ StreamTagger.TrackInfoMerge (track, file, false, true);
+ }
track.PrimarySource = trackPrimarySourceChooser (track);
diff --git a/src/Core/Banshee.Services/Banshee.Collection/RescanPipeline.cs b/src/Core/Banshee.Services/Banshee.Collection/RescanPipeline.cs
index 66f2416..d143a5a 100644
--- a/src/Core/Banshee.Services/Banshee.Collection/RescanPipeline.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection/RescanPipeline.cs
@@ -214,8 +214,9 @@ namespace Banshee.Collection
// If the file was modified since we last scanned, parse the file's metadata
if (mtime > track.FileModifiedStamp) {
- TagLib.File file = Banshee.Streaming.StreamTagger.ProcessUri (track.Uri);
- Banshee.Streaming.StreamTagger.TrackInfoMerge (track, file, false);
+ using (var file = Banshee.Streaming.StreamTagger.ProcessUri (track.Uri)) {
+ Banshee.Streaming.StreamTagger.TrackInfoMerge (track, file, false);
+ }
}
}
}
diff --git a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
index bf66e5f..93aa331 100644
--- a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
+++ b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
@@ -1378,8 +1378,9 @@ namespace Banshee.Database
if (track != null && track.Uri != null && track.Uri.IsFile) {
try {
- TagLib.File file = StreamTagger.ProcessUri (track.Uri);
- StreamTagger.TrackInfoMerge (track, file, true);
+ using (var file = StreamTagger.ProcessUri (track.Uri)) {
+ StreamTagger.TrackInfoMerge (track, file, true);
+ }
} catch (Exception e) {
Log.Warning (String.Format ("Failed to update metadata for {0}", track),
e.GetType ().ToString (), false);
diff --git a/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs b/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs
index cc4ab5a..3b6a5eb 100644
--- a/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs
+++ b/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs
@@ -88,14 +88,9 @@ namespace Banshee.Metadata.Embedded
protected IPicture [] GetEmbeddedPictures(SafeUri uri)
{
- TagLib.File file = StreamTagger.ProcessUri(uri);
- if (file != null) {
- var pics = file.Tag.Pictures;
- file.Mode = TagLib.File.AccessMode.Closed;
- return pics;
+ using (var file = StreamTagger.ProcessUri (uri)) {
+ return file == null ? null : file.Tag.Pictures;
}
-
- return null;
}
protected int GetPictureIndexToUse(IPicture [] pictures)
diff --git a/src/Core/Banshee.Services/Banshee.Metadata/Tests/TaglibReadWriteTests.cs b/src/Core/Banshee.Services/Banshee.Metadata/Tests/TaglibReadWriteTests.cs
index 2478872..d4a7652 100644
--- a/src/Core/Banshee.Services/Banshee.Metadata/Tests/TaglibReadWriteTests.cs
+++ b/src/Core/Banshee.Services/Banshee.Metadata/Tests/TaglibReadWriteTests.cs
@@ -179,6 +179,7 @@ namespace Banshee.Metadata
TagLib.File file = StreamTagger.ProcessUri (uri);
TrackInfo track = new TrackInfo ();
StreamTagger.TrackInfoMerge (track, file);
+ file.Dispose ();
// Make changes
change (track);
@@ -191,6 +192,7 @@ namespace Banshee.Metadata
file = StreamTagger.ProcessUri (uri);
track = new TrackInfo ();
StreamTagger.TrackInfoMerge (track, file, false, true);
+ file.Dispose ();
// Verify changes
verify (track);
diff --git a/src/Core/Banshee.Services/Banshee.Streaming/RadioTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Streaming/RadioTrackInfo.cs
index 89ef998..0ccbe50 100644
--- a/src/Core/Banshee.Services/Banshee.Streaming/RadioTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Streaming/RadioTrackInfo.cs
@@ -215,8 +215,9 @@ namespace Banshee.Streaming
Log.Debug("Playing Radio Stream", Uri.AbsoluteUri);
if (Uri.IsFile) {
try {
- TagLib.File file = StreamTagger.ProcessUri (Uri);
- StreamTagger.TrackInfoMerge (this, file, true);
+ using (var file = StreamTagger.ProcessUri (Uri)) {
+ StreamTagger.TrackInfoMerge (this, file, true);
+ }
} catch (Exception e) {
Log.Warning (String.Format ("Failed to update metadata for {0}", this),
e.GetType ().ToString (), false);
diff --git a/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs b/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs
index 6a88d97..aff9f0e 100644
--- a/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs
+++ b/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs
@@ -211,7 +211,9 @@ namespace Banshee.AudioCd
track.FileModifiedStamp = Banshee.IO.File.GetModifiedTime (track.Uri);
track.LastSyncedStamp = DateTime.Now;
- StreamTagger.TrackInfoMerge (track, StreamTagger.ProcessUri (track.Uri), true);
+ using (var file = StreamTagger.ProcessUri (track.Uri)) {
+ StreamTagger.TrackInfoMerge (track, file, true);
+ }
track.Save ();
diff --git a/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs b/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
index dedf14f..8d28ca0 100644
--- a/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
+++ b/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
@@ -193,8 +193,9 @@ namespace Banshee.LibraryWatcher
if (reader.Read ()) {
var track_info = DatabaseTrackInfo.Provider.Load (reader);
if (Banshee.IO.File.GetModifiedTime (track_info.Uri) > track_info.FileModifiedStamp) {
- var file = StreamTagger.ProcessUri (track_info.Uri);
- StreamTagger.TrackInfoMerge (track_info, file, false);
+ using (var file = StreamTagger.ProcessUri (track_info.Uri)) {
+ StreamTagger.TrackInfoMerge (track_info, file, false);
+ }
track_info.LastSyncedStamp = DateTime.Now;
track_info.Save (false);
}
@@ -284,7 +285,9 @@ namespace Banshee.LibraryWatcher
var uri = new SafeUri (item.FullPath);
if (DatabaseImportManager.IsWhiteListedFile (item.FullPath) && Banshee.IO.File.Exists (uri)) {
var track = new TrackInfo ();
- StreamTagger.TrackInfoMerge (track, StreamTagger.ProcessUri (uri));
+ using (var file = StreamTagger.ProcessUri (uri)) {
+ StreamTagger.TrackInfoMerge (track, file);
+ }
item.MetadataHash = track.MetadataHash;
}
}
diff --git a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs
index 0f8c509..27ddf1b 100644
--- a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs
+++ b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs
@@ -207,8 +207,9 @@ namespace Banshee.Podcasting.Data
if (!String.IsNullOrEmpty (Item.Enclosure.LocalPath)) {
try {
- TagLib.File file = Banshee.Streaming.StreamTagger.ProcessUri (track.Uri);
- Banshee.Streaming.StreamTagger.TrackInfoMerge (track, file, true);
+ using (var file = Banshee.Streaming.StreamTagger.ProcessUri (track.Uri)) {
+ Banshee.Streaming.StreamTagger.TrackInfoMerge (track, file, true);
+ }
} catch {}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]