1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-26 12:42:29 +01:00

ensure PathFormat.directory ends with a path separator

... plus some other small optimizations
This commit is contained in:
Mike Fährmann 2019-08-20 00:25:13 +02:00
parent ebabc5caf1
commit 3284c62f22
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 15 additions and 17 deletions

View File

@ -47,10 +47,9 @@ class ClassifyPP(PostProcessor):
@staticmethod @staticmethod
def _build_paths(pathfmt, extra): def _build_paths(pathfmt, extra):
path = pathfmt.realdirectory + os.sep + extra path = pathfmt.realdirectory + extra
pathfmt.realpath = path + os.sep + pathfmt.filename pathfmt.realpath = path + os.sep + pathfmt.filename
pathfmt.path = (pathfmt.directory + os.sep + pathfmt.path = pathfmt.directory + extra + os.sep + pathfmt.filename
extra + os.sep + pathfmt.filename)
return path return path

View File

@ -546,12 +546,13 @@ class PathFormat():
self.delete = False self.delete = False
self.path = self.realpath = self.temppath = "" self.path = self.realpath = self.temppath = ""
self.basedirectory = expand_path( basedir = expand_path(
extractor.config("base-directory", (".", "gallery-dl"))) extractor.config("base-directory", (".", "gallery-dl")))
if os.altsep and os.altsep in self.basedirectory: if os.altsep and os.altsep in basedir:
self.basedirectory = self.basedirectory.replace(os.altsep, os.sep) basedir = basedir.replace(os.altsep, os.sep)
if self.basedirectory[-1] != os.sep: if basedir[-1] != os.sep:
self.basedirectory += os.sep basedir += os.sep
self.basedirectory = basedir
restrict = extractor.config("path-restrict", "auto") restrict = extractor.config("path-restrict", "auto")
if restrict == "auto": if restrict == "auto":
@ -616,18 +617,17 @@ class PathFormat():
raise exception.FormatError(exc, "directory") raise exception.FormatError(exc, "directory")
# Join path segements # Join path segements
directory = self.clean_path( sep = os.sep
self.basedirectory + os.sep.join(segments)) directory = self.clean_path(self.basedirectory + sep.join(segments))
# Remove trailing path separator; # Ensure directory ends with a path separator
# occurs if the last segment is an empty string if directory[-1] != sep:
if directory[-1] == os.sep: directory += sep
directory = directory[:-1]
self.directory = directory self.directory = directory
# Enable longer-than-260-character paths on Windows # Enable longer-than-260-character paths on Windows
if os.name == "nt": if os.name == "nt":
self.realdirectory = "\\\\?\\" + os.path.abspath(directory) self.realdirectory = "\\\\?\\" + os.path.abspath(directory) + sep
else: else:
self.realdirectory = directory self.realdirectory = directory
@ -664,13 +664,12 @@ class PathFormat():
# Apply 'kwdict' to filename format string # Apply 'kwdict' to filename format string
try: try:
self.filename = self.clean_path(self.clean_segment( self.filename = filename = self.clean_path(self.clean_segment(
self.filename_formatter(self.kwdict))) self.filename_formatter(self.kwdict)))
except Exception as exc: except Exception as exc:
raise exception.FormatError(exc, "filename") raise exception.FormatError(exc, "filename")
# Combine directory and filename to full paths # Combine directory and filename to full paths
filename = os.sep + self.filename
self.path = self.directory + filename self.path = self.directory + filename
self.realpath = self.realdirectory + filename self.realpath = self.realdirectory + filename
if not self.temppath: if not self.temppath: