mirror of
https://github.com/beetbox/beets.git
synced 2026-01-04 23:12:51 +01:00
look up max filename length automatically
This commit is contained in:
parent
f652662d5b
commit
d4ddfd1091
2 changed files with 20 additions and 5 deletions
|
|
@ -1152,6 +1152,7 @@ class Library(BaseLibrary):
|
|||
"""
|
||||
pathmod = pathmod or os.path
|
||||
platform = platform or sys.platform
|
||||
basedir = basedir or self.directory
|
||||
|
||||
# Use a path format based on a query, falling back on the
|
||||
# default.
|
||||
|
|
@ -1197,15 +1198,15 @@ class Library(BaseLibrary):
|
|||
subpath += extension.lower()
|
||||
|
||||
# Truncate too-long components.
|
||||
subpath = util.truncate_path(
|
||||
subpath, pathmod,
|
||||
beets.config['max_filename_length'].get(int),
|
||||
)
|
||||
maxlen = beets.config['max_filename_length'].get(int)
|
||||
if not maxlen:
|
||||
# When zero, try to determine from filesystem.
|
||||
maxlen = util.max_filename_length(self.directory)
|
||||
subpath = util.truncate_path(subpath, pathmod, maxlen)
|
||||
|
||||
if fragment:
|
||||
return subpath
|
||||
else:
|
||||
basedir = basedir or self.directory
|
||||
return normpath(os.path.join(basedir, subpath))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -601,3 +601,17 @@ def command_output(cmd):
|
|||
if proc.returncode:
|
||||
raise subprocess.CalledProcessError(proc.returncode, cmd)
|
||||
return stdout
|
||||
|
||||
def max_filename_length(path, fallback=MAX_FILENAME_LENGTH):
|
||||
"""Attempt to determine the maximum filename length for the
|
||||
filesystem containing `path`. If it cannot be determined, return a
|
||||
predetermined fallback value.
|
||||
"""
|
||||
if hasattr(os, 'statvfs'):
|
||||
try:
|
||||
res = os.statvfs(path)
|
||||
except OSError:
|
||||
return fallback
|
||||
return res[9]
|
||||
else:
|
||||
return fallback
|
||||
|
|
|
|||
Loading…
Reference in a new issue