mirror of
https://github.com/beetbox/beets.git
synced 2026-01-06 16:02:53 +01:00
truncate path components to 30 characters on Windows (work around #120)
This commit is contained in:
parent
ca0d1bc7aa
commit
ab35db7b7a
3 changed files with 13 additions and 2 deletions
1
NEWS
1
NEWS
|
|
@ -20,6 +20,7 @@
|
|||
completely wrong association of track names to files. The order
|
||||
applied was always just alphabetical by filename, which is frequently
|
||||
but not always what you want.
|
||||
* Filenames are now truncated to 30 characters on Windows.
|
||||
* Fix crash in lastid when the artist name is not available.
|
||||
* Fixed a spurious crash when LANG or a related environment variable is
|
||||
set to an invalid value (such as 'UTF-8' on some installations of Mac
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ from beets.mediafile import MediaFile, UnreadableFileError, FileTypeError
|
|||
from beets import plugins
|
||||
|
||||
MAX_FILENAME_LENGTH = 200
|
||||
MAX_WINDOWS_FILENAME_LENGTH = 30
|
||||
|
||||
# Fields in the "items" database table; all the metadata available for
|
||||
# items in the library. These are used directly in SQL; they are
|
||||
|
|
@ -203,8 +204,9 @@ def _sanitize_path(path, pathmod=None):
|
|||
comp = regex.sub(repl, comp)
|
||||
|
||||
# Truncate each component.
|
||||
if len(comp) > MAX_FILENAME_LENGTH:
|
||||
comp = comp[:MAX_FILENAME_LENGTH]
|
||||
maxlen = MAX_WINDOWS_FILENAME_LENGTH if windows else MAX_FILENAME_LENGTH
|
||||
if len(comp) > maxlen:
|
||||
comp = comp[:maxlen]
|
||||
|
||||
comps[i] = comp
|
||||
return pathmod.join(*comps)
|
||||
|
|
|
|||
|
|
@ -259,6 +259,14 @@ class DestinationTest(unittest.TestCase):
|
|||
p = beets.library._sanitize_path(u':', posixpath)
|
||||
self.assertEqual(p, u'-')
|
||||
|
||||
def test_sanitize_windows_uses_very_short_names(self):
|
||||
p = beets.library._sanitize_path('X'*300 + '/' + 'Y'*200, ntpath)
|
||||
self.assertLessEqual(len(p), 100)
|
||||
|
||||
def test_sanitize_unix_uses_longer_names(self):
|
||||
p = beets.library._sanitize_path('X'*300 + '/' + 'Y'*200, posixpath)
|
||||
self.assertGreaterEqual(len(p), 100)
|
||||
|
||||
def test_path_with_format(self):
|
||||
self.lib.path_format = '$artist/$album ($format)'
|
||||
p = self.lib.destination(self.i)
|
||||
|
|
|
|||
Loading…
Reference in a new issue