Skip to content

Commit

Permalink
Fix suffix swallowing for non-tar output path.
Browse files Browse the repository at this point in the history
If the user enters "-o Foo.bar.baz", they expect the tarball name to be
"Foo.bar.baz.tar.?z", not "Foo.bar.tar.?z". We were getting the latter
due to the use of "Path().with_suffix('.tar')" which removes the last
suffix in Path irrespective of what it is. Fixed by simply appending
.tar to the name instead of suffix swallowing.
  • Loading branch information
badshah400 committed Feb 15, 2024
1 parent 4c89778 commit 2faf48f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/tartex/tartex.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def __init__(self, args):
self.tar_ext = "xz"

tar_base = (
Path(self.args.output).with_suffix(".tar").expanduser()
Path(f"{self.args.output}.tar").expanduser()
if self.args.output
else Path(self.main_file.stem).with_suffix(".tar")
else Path(f"{self.args.output}.tar")
)
self.tar_file = self.cwd / tar_base # The '/' operation returns tar_base
# if it is an absolute path
Expand Down Expand Up @@ -587,9 +587,9 @@ def _proc_output_path(self):
Also sets the tar ext if determined from '--output' argument.
"""

out = Path(self.args.output)
if not out.is_absolute(): # Resolve w.r.t. cwd if relative path
out = self.cwd / out
out = self.cwd / self.args.output # If self.args.output is absolute,
# '/' simply returns it as a PosixPath

if out.is_dir(): # If dir, set to DIR/main.tar.gz
log.debug("%s is an existing dir", out)
out = out.joinpath(
Expand Down

0 comments on commit 2faf48f

Please sign in to comment.