Skip to content

Commit

Permalink
Fix duplicate pkg registration overwriting the existing pkg
Browse files Browse the repository at this point in the history
Update the tests:
- Enable and rename the duplicate_pkgs test to duplicate_pkgs_allowed,
  to make it more clear which we are testing.  Also switch to using the
  new_pkg function to make the test cleaner.
- Add a disabled duplicate_pkgs_allowed test in prep for that being supported.
- Teach the register_message test to use new_manifest() and fix the duplicate
  registration it was doing.
  • Loading branch information
brd authored and bapt committed Jul 31, 2017
1 parent d33ebc0 commit 7991c49
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
4 changes: 4 additions & 0 deletions libpkg/pkg_ports.c
Expand Up @@ -1289,6 +1289,10 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
UT_string *message;
struct pkg_message *msg;

if (pkg_is_installed(db, pkg->name) != EPKG_END) {
return(EPKG_INSTALLED);
}

location = reloc;
if (pkg_rootdir != NULL)
location = pkg_rootdir;
Expand Down
45 changes: 28 additions & 17 deletions tests/frontend/config.sh
Expand Up @@ -3,31 +3,19 @@
. $(atf_get_srcdir)/test_environment.sh
tests_init \
empty_conf \
duplicate_pkgs_notallowed \
inline_repo \
nameserver
#duplicate_pkgs
# duplicate_pkgs_allowed \

# This test is half finished to show problems with `pkg register'
duplicate_pkgs_body() {
duplicate_pkgs_allowed_body() {
cat << EOF > pkg.conf
duplicatedefault: 2
EOF

for n in 1 2; do
cat << EOF > test${n}.ucl
name: test
origin: test
version: ${n}
allowduplicate: true
maintainer: test
categories: [test]
comment: a test
www: http://test
prefix: /
desc: <<EOD
Yet another test
EOD
EOF
new_pkg test${n} test ${n}
echo 'allowduplicate: true' >> test${n}.ucl

atf_check \
-e empty \
Expand All @@ -44,6 +32,29 @@ done
pkg info
}

duplicate_pkgs_notallowed_body() {
for n in 1 2; do
new_pkg test${n} test ${n}
done

atf_check \
-e empty \
-o match:"Installing test-1..." \
-s exit:0 \
pkg register -M test1.ucl

atf_check \
-e empty \
-s exit:70 \
pkg register -M test1.ucl

atf_check \
-e empty \
-o match:"test-1 a test" \
-s exit:0 \
pkg info
}

empty_conf_body() {
touch pkg.conf

Expand Down
17 changes: 4 additions & 13 deletions tests/frontend/register.sh
Expand Up @@ -58,29 +58,20 @@ EOF
}

register_message_body() {
cat << EOF > +MANIFEST
name: "test2"
origin: "osef"
version: "1"
arch: "freebsd:*"
maintainer: "non"
prefix: "${TMPDIR}"
www: "unknown"
comment: "need one"
desc: "here as well"
EOF
new_manifest test1 1 "${TMPDIR}"
cat << EOF > +DISPLAY
message
EOF

OUTPUT='test2-1:
OUTPUT='test1-1:
Always:
message
'
atf_check -o match:"message" pkg register -m .
atf_check -o inline:"${OUTPUT}" pkg info -D test2
atf_check -o inline:"${OUTPUT}" pkg info -D test1

new_manifest test2 1 "${TMPDIR}"
cat << EOF > +DISPLAY
[
{ message: "hey"},
Expand Down

4 comments on commit 7991c49

@lattera
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks make reinstall in ports.

@bapt
Copy link
Member

@bapt bapt commented on 7991c49 Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it should have always been like that, the real reinstallation was make deinstall reinstall, the fact one needs not to run deinstall first was a bug introduced very very long ago

@lattera
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that documented anywhere?

@lattera
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yup: in the ports(7) manpage.

Please sign in to comment.