[banshee] Importing: skip empty files and show error



commit 0a39dfd2139cc2143a3393594aa6eed0269c68f1
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Sun Nov 27 04:29:41 2011 +0000

    Importing: skip empty files and show error
    
    There was no visible sign for the user that the
    track was invalid because its file size was zero.
    This can lead to elements in the library that
    cannot be played and which cannot be synced to
    any device.
    
    Fixes bgo#664079

 .../DatabaseImportManager.cs                       |    6 +++
 .../Banshee.Collection/InvalidFileException.cs     |   38 ++++++++++++++++++++
 src/Core/Banshee.Services/Banshee.Services.csproj  |    1 +
 src/Core/Banshee.Services/Makefile.am              |    1 +
 4 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
index 73fa668..1be82ae 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
@@ -168,6 +168,12 @@ namespace Banshee.Collection.Database
                 return null;
             }
 
+            if (Banshee.IO.File.GetSize (uri) == 0) {
+                throw new InvalidFileException (String.Format (
+                    Catalog.GetString ("File is empty so it could not be imported: {0}"),
+                    Path.GetFileName (uri.LocalPath)));
+            }
+
             DatabaseTrackInfo track = new DatabaseTrackInfo () { Uri = uri };
             using (var file = StreamTagger.ProcessUri (uri)) {
                 StreamTagger.TrackInfoMerge (track, file, false, true);
diff --git a/src/Core/Banshee.Services/Banshee.Collection/InvalidFileException.cs b/src/Core/Banshee.Services/Banshee.Collection/InvalidFileException.cs
new file mode 100644
index 0000000..55ec475
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Collection/InvalidFileException.cs
@@ -0,0 +1,38 @@
+// 
+// InvalidFileException.cs
+// 
+// Author:
+//   AndrÃs G. Aragoneses <knocte gmail com>
+// 
+// Copyright 2011 AndrÃs G. Aragoneses
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+
+namespace Banshee.Collection
+{
+    public class InvalidFileException : ApplicationException
+    {
+        public InvalidFileException (string message) : base (message)
+        {
+        }
+    }
+}
+
diff --git a/src/Core/Banshee.Services/Banshee.Services.csproj b/src/Core/Banshee.Services/Banshee.Services.csproj
index 5d4f875..804478a 100644
--- a/src/Core/Banshee.Services/Banshee.Services.csproj
+++ b/src/Core/Banshee.Services/Banshee.Services.csproj
@@ -326,6 +326,7 @@
     <Compile Include="Banshee.Collection.Database\DatabaseAlbumArtistListModel.cs" />
     <Compile Include="Banshee.Collection.Database\DatabaseYearInfo.cs" />
     <Compile Include="Banshee.Collection.Database\DatabaseYearListModel.cs" />
+    <Compile Include="Banshee.Collection\InvalidFileException.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Banshee.Services.addin.xml">
diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am
index d952b31..935cec9 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -52,6 +52,7 @@ SOURCES =  \
 	Banshee.Collection/IFilterListModel.cs \
 	Banshee.Collection/ImportEventHandler.cs \
 	Banshee.Collection/ImportManager.cs \
+	Banshee.Collection/InvalidFileException.cs \
 	Banshee.Collection/MemoryTrackListModel.cs \
 	Banshee.Collection/ModelHelper.cs \
 	Banshee.Collection/RescanPipeline.cs \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]