Skip to content

Commit

Permalink
generator: trim 255 char filenames for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
bnnm committed Aug 8, 2021
1 parent cb967f8 commit 4399cbd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions wwiser/wtxtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
from . import wgamesync, wtxtp_tree, wtxtp_info, wversion


#use a bit less than 255 so files can be moved around dirs
#long paths can be enabled on Windows but detection+support is messy...
# use a bit less than 255 so files can be moved around dirs
# long paths can be enabled on Windows + python but detection+support is messy...
# (if not trimmed python may give an error on open W, even if individual path elems are less than 255)
WINDOWS_MAX_PATH = 240

# use a bit less than 255 for "base" filenames, too
# (max filename length on Linux is 255, even if dirs + name can be more than that
MAX_FILENAME_LENGTH = 240

# Builds a TXTP tree from original CAkSound/etc nodes, recreated as a playlist to simplify generation.
#
# For example a path like this:
Expand Down Expand Up @@ -224,6 +229,14 @@ def _write_txtp(self, printer):
outdir = os.path.join(self._basepath, outdir)
os.makedirs(outdir, exist_ok=True)

# enforce max filename (few OSes support more than that)
if len(name) > MAX_FILENAME_LENGTH:
if not longname:
longname = name
name = "%s~%04i%s" % (name[0:MAX_FILENAME_LENGTH], self.txtpcache.created, '.txtp')
self.txtpcache.trims += 1
logging.debug("txtp: trimmed name '%s'", name)

outname = outdir + name

info = self._get_info(name, longname)
Expand All @@ -235,7 +248,7 @@ def _write_txtp(self, printer):
maxlen = WINDOWS_MAX_PATH - len(self.txtpcache.basedir) - 10
outname = "%s~%04i%s" % (outname[0:maxlen], self.txtpcache.created, '.txtp')
self.txtpcache.trims += 1
logging.debug("txtp: trimmed '%s'", outname)
logging.debug("txtp: trimmed path '%s'", outname)

if self.txtpcache.x_notxtp:
return
Expand Down

0 comments on commit 4399cbd

Please sign in to comment.