Skip to content

Commit

Permalink
Fix tar regular expr and improve related test
Browse files Browse the repository at this point in the history
It seems GNAT's Normalize_Arguments does its own escaping, so we do not need to
do it ourselves. Also, the test checks that indeed the `alire` folder is
excluded when tar'ing manually.
  • Loading branch information
mosteo committed Sep 17, 2020
1 parent 89aef8f commit 7e42eef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/alire/alire-publish.adb
Expand Up @@ -331,22 +331,24 @@ package body Alire.Publish is
& "cfj"
& Archive -- Destination file at alire/archives/crate-version.tbz2

& String'("--exclude=./alire")
-- Exclude top-level alire folder, before applying prefix

-- exclude .git and the like, with workaround for macOS bsd tar
& (if GNATCOLL.OS.Constants.OS in GNATCOLL.OS.MacOS
then Empty_Vector
& "--exclude='./.git'"
& "--exclude='./.hg'"
& "--exclude='./.svn'"
& String'("-s,^\./," & Milestone & "/,")
& "--exclude=./.git"
& "--exclude=./.hg"
& "--exclude=./.svn"
& String'("-s,^./," & Milestone & "/,")
-- Prepend empty milestone dir as required for our tars)
else Empty_Vector
& "--exclude-backups" -- exclude .#* *~ #*# patterns
& "--exclude-vcs" -- exclude .git, .hg, etc
& "--exclude-vcs-ignores" -- exclude from .gitignore, etc
& String'("--transform=s,^\./," & Milestone & "/,"))
& String'("--transform=s,^./," & Milestone & "/,"))
-- Prepend empty milestone dir as required for our tars

& "--exclude='./alire'" -- exclude top-level alire folder
& ".");
pragma Warnings (On);
end Tar_Archive;
Expand Down
19 changes: 19 additions & 0 deletions testsuite/tests/publish/tarball-plaindir/test.py
Expand Up @@ -3,21 +3,36 @@
"""

from drivers.alr import init_local_crate, run_alr
from glob import glob
from shutil import copyfile
from subprocess import run

import drivers.helpers
import os

# Prepare our "remote" repo
init_local_crate("xxx", enter=True)

canary = "canary.txt"

# Create a canary file to double-check that it does not make into the tarball
with open(os.path.join("alire", canary), "wt") as file:
print(file, "...\n")

# Publish it. We need to give input to alr, so we directly call it. We use the
# generated location as the "online" location, and this works because we are
# forcing.
p = run(["alr", "publish", "--skip-build", "--tar", "-q", "-f", "-n"],
input=f"file:{os.getcwd()}/alire/archives/xxx-0.0.0.tbz2\n".encode())
p.check_returncode()

# Verify the generated file does not contain the alire folder
p = run(["tar", "tf", "alire/archives/xxx-0.0.0.tbz2"],
capture_output=True)
p.check_returncode()
assert "xxx-0.0.0/alire/" not in p.stdout.decode(), \
"Unexpected contents in tarball: " + p.stdout.decode()

# Verify the index manifest has been generated
assert os.path.isfile("./alire/releases/xxx-0.0.0.toml")

Expand All @@ -30,4 +45,8 @@

run_alr("get", "--build", "xxx") # Should not err

# Verify the canary didn't made through
os.chdir(glob("xxx*")[0])
assert not os.path.isfile(os.path.join("alire", canary))

print('SUCCESS')

0 comments on commit 7e42eef

Please sign in to comment.