[banshee] PathPattern: Limit filename length to 200 characters (bgo#636450)



commit f24e62a2970fc08b91ad334737ed658623695906
Author: Roderich Schupp <roderich schupp googlemail com>
Date:   Wed Sep 12 21:08:20 2012 +0200

    PathPattern: Limit filename length to 200 characters (bgo#636450)
    
    If a track has a really long title, we would reach the limit of the
    filesystem and fail to write it. In particular, this lead to crashes
    when ripping some CDs.
    
    On most filesystems, filenames are limited to 255 characters or 255
    bytes. As we can't be sure of the byte size when the filename reaches
    the filesystem, we use an arbitrary limit of 200 characters. This should
    be enough to be safe in most cases, without being too limiting.
    
    Signed-off-by: Bertrand Lorentz <bertrand lorentz gmail com>

 src/Core/Banshee.Core/Banshee.Base/PathPattern.cs |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/src/Core/Banshee.Core/Banshee.Base/PathPattern.cs b/src/Core/Banshee.Core/Banshee.Base/PathPattern.cs
index 1f202fa..1c61fe3 100644
--- a/src/Core/Banshee.Core/Banshee.Base/PathPattern.cs
+++ b/src/Core/Banshee.Core/Banshee.Base/PathPattern.cs
@@ -167,17 +167,23 @@ namespace Banshee.Base
                 ext = String.Format (".{0}", ext);
             }
 
-            string songpath = CreateFromTrackInfo (track) + ext;
+            string songpath = CreateFromTrackInfo (track);
             songpath = Hyena.StringUtil.EscapePath (songpath);
+
             string dir = Path.GetFullPath (Path.Combine (base_dir,
                 Path.GetDirectoryName (songpath)));
-            string filename = Path.Combine (dir, Path.GetFileName (songpath));
-
             if (!Banshee.IO.Directory.Exists (dir)) {
                 Banshee.IO.Directory.Create (dir);
             }
 
-            return filename;
+            string filename = Path.GetFileName (songpath);
+            // Most filesystems have a filename length limit of 255 characters or bytes
+            // We use a limit of 200 characters as a compromise
+            if (filename.Length > 200) {
+                filename = filename.Remove (200);
+            }
+
+            return Path.Combine (dir, filename + ext);
         }
 
         public static string Escape (string input)



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