[banshee] Dap.MassStorage: not import dirs twice for case-insensitive drives (bgo#653282)



commit 1eb9f5f0e7304e0c32af354a5b79a2668353b783
Author: Nicholas Little <arealityfarbetween googlemail com>
Date:   Mon Jan 14 21:54:01 2013 +0000

    Dap.MassStorage: not import dirs twice for case-insensitive drives (bgo#653282)
    
    Case insensitive file-systems, when imported via the MassStorage extension,
    could include duplicate entries because the default folders configured could
    contain directory names that were equivalent, i.e. /Music and /music.
    
    A more thorough check could have been done creating a file and checking that
    the file content is the same even if queried with a different case, but:
    - That would require read/write access, which we cannot guarantee.
    - Is less safe (could overwrite an existing file) and less elegant.
    
    A list of case insensitive file-systems types that Banshee is aware of, is
    good enough approach then.
    
    Signed-off-by: Andres G. Aragoneses <knocte gmail com>

 .../Banshee.Hardware/FileSystem.cs                 |   44 ++++++++++++++++++++
 src/Core/Banshee.Services/Banshee.Services.csproj  |    1 +
 src/Core/Banshee.Services/Makefile.am              |    1 +
 .../Banshee.Dap.MassStorage/MassStorageDevice.cs   |   12 ++++-
 4 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Hardware/FileSystem.cs b/src/Core/Banshee.Services/Banshee.Hardware/FileSystem.cs
new file mode 100644
index 0000000..6abc9ad
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Hardware/FileSystem.cs
@@ -0,0 +1,44 @@
+//
+// FileSystem.cs
+//
+// Author:
+//   Nicholas Little <arealityfarbetween googlemail com>
+//
+// Copyright 2013 Nicholas Little
+//
+// 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;
+using System.IO;
+using System.Linq;
+
+namespace Banshee.Hardware
+{
+    public static class FileSystem
+    {
+        public static bool IsCaseSensitive (IVolume volume)
+        {
+            var drive = new DriveInfo (volume.MountPoint);
+            return !case_insensitive_filesystems.Contains (drive.DriveFormat);
+        }
+
+        private static readonly string[] case_insensitive_filesystems = { "vfat", "msdos", "ntfs" };
+    }
+}
+
diff --git a/src/Core/Banshee.Services/Banshee.Services.csproj b/src/Core/Banshee.Services/Banshee.Services.csproj
index 83ae213..a525dd9 100644
--- a/src/Core/Banshee.Services/Banshee.Services.csproj
+++ b/src/Core/Banshee.Services/Banshee.Services.csproj
@@ -329,6 +329,7 @@
     <Compile Include="Banshee.Collection\InvalidFileException.cs" />
     <Compile Include="Banshee.Sources\IBatchScrobblerSource.cs" />
     <Compile Include="Banshee.Playlists.Formats\PlaylistElement.cs" />
+    <Compile Include="Banshee.Hardware\FileSystem.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 f73a7c4..f2aac96 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -69,6 +69,7 @@ SOURCES =  \
 	Banshee.Equalizer/EqualizerManager.cs \
 	Banshee.Equalizer/EqualizerSetting.cs \
 	Banshee.Hardware/DeviceCommand.cs \
+	Banshee.Hardware/FileSystem.cs \
 	Banshee.Hardware/HardwareManager.cs \
 	Banshee.Hardware/IBlockDevice.cs \
 	Banshee.Hardware/ICdromDevice.cs \
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
index a1970ab..dd4ca94 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
@@ -116,8 +116,16 @@ namespace Banshee.Dap.MassStorage
             cover_art_file_type = GetPreferredValue ("cover_art_file_type", config, DefaultCoverArtFileType);
             cover_art_file_name = GetPreferredValue ("cover_art_file_name", config, DefaultCoverArtFileName);
             cover_art_size = GetPreferredValue ("cover_art_size", config, DefaultCoverArtSize);
-            audio_folders = MergeValues ("audio_folders", config, DefaultAudioFolders);
-            video_folders = MergeValues ("video_folders", config, DefaultVideoFolders);
+
+            var all_audio_folders = MergeValues ("audio_folders", config, DefaultAudioFolders);
+            var all_video_folders = MergeValues ("video_folders", config, DefaultVideoFolders);
+            if (!FileSystem.IsCaseSensitive (source.Volume)) {
+                all_audio_folders = all_audio_folders.Distinct (StringComparer.CurrentCultureIgnoreCase).ToArray ();
+                all_video_folders = all_video_folders.Distinct (StringComparer.CurrentCultureIgnoreCase).ToArray ();
+            }
+            audio_folders = all_audio_folders;
+            video_folders = all_audio_folders;
+
             playback_mime_types = MergeValues ("output_formats", config, DefaultPlaybackMimeTypes);
             playlist_formats = MergeValues ("playlist_formats", config, DefaultPlaylistFormats);
             var playlist_path = GetPreferredValue ("playlist_path", config, DefaultPlaylistPath);



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