Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports from Parabola #5

Merged

Conversation

LukeShu
Copy link
Contributor

@LukeShu LukeShu commented Mar 14, 2018

These are commits from Parabola's dbscripts that I think are
upstreamable. No real theme to them, but because some of them are
wide-sweeping (eg. clean up quoting), they are a good base layer to
apply before backporting other changes.

I've done my best to look over them, but at least one weird thing did
happen while rebasing them, so it's possible I missed something that
rebased weird.

Some of this duplicates (non-backported) changes in the last patchset
I submitted.

This is currently v2 of the patchset. v1 was submitted on the mailing list. I'm submitting v2 here to get a shiny little confirmation from Travis that I didn't break anything; I'm submitting it to the mailing list as well.

@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from bb337fd to 795b654 Compare March 14, 2018 05:45
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 14, 2018

Huh, Travis ran slightly faster than my local make test. Eli's awk expression in the final commit. I've pushed a revised version. I'm going to bed. If in the morning Travis/make test came back saying we're good, I'll also send it to the mailing list.

Copy link
Contributor

@eli-schwartz eli-schwartz left a comment

Choose a reason for hiding this comment

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

As I said on the mailing list, I don't see the need to overquote variables everywhere. You want it for the sake of linting (this is a shellcheck thing I actually disagree with) and to reduce the diff against your fork (which is not our design goal).

I'm not sure what to do about it.

# Should this package be skipped?
if grep -Fqx "${pkgbase}" "${dirname}/sourceballs.skip"; then
continue
fi
# Check if the license or .force file does not enforce creating a source package
if ! ([[ -z ${ALLOWED_LICENSES[@]} ]] || chk_license ${pkglicense[@]} || grep -Fqx "${pkgbase}" "${dirname}/sourceballs.force"); then
if ! ([[ ${#ALLOWED_LICENSES[@]} == 0 ]] || chk_license "${pkglicense[@]}" || grep -Fqx "${pkgbase}" "${dirname}/sourceballs.force"); then
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of string comparisons why not use shell arithmetic?

db-functions Outdated
@@ -282,7 +282,7 @@ getpkgfile() {

getpkgfiles() {
local f files
if [[ ! -z "$(printf '%s\n' "${@%\.*}" | sort | uniq -D)" ]]; then
if ! printf '%s\n' "${@%\.*}" | awk 'a[$0]++>1{exit 1}'; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not fix this all at once instead of changing the same line multiple times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's two logically distinct changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

And so are several other changes you lumped into the first commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're all "this array wasn't quoted, but we can do a better fix than simply quoting it"

db-functions Outdated
else
return 1
fi
[[ ${pkgfile##*/} == "${pkgname}-${pkgver}-${pkgarch}"* ]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use ==, use = instead. This is a weird bash extension that literally serves no purpose as it merely aliases =.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[[ is a weird bash extension.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it is a cool bash extension that serves a purpose. You've added the only two examples of using == in the main code, just now, and I dispute Chet Ramey's reasons for adding the == alias to the bash scripting language as it adds no utility to the language while adding compatibility to C as an anti-feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Glob/regex matching, but the rest of it is weird. [[ -r $filename ]] adds nothing to the language, and serves no purpose over [ -r "$filename" ]

At the end of the day, it's just a style choice. And that's fine. But "it's the codebase's style" is the winning argument there, not "it's a bad extension". I hadn't realized that the main codebase was all =; I'd though it was inconsistent; I hadn't realized that all of the [[ == ]] uses were in test/.

indirect="${var}_backup"
if [ -n "${!indirect}" ]; then
eval "${var}=(\${$indirect[@]})"
eval "${var}=(\"\${$indirect[@]}\")"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would still like to fix this by avoiding the issue entirely and using declare as I mentioned on the mailing list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. From the ML:

Maybe I should fix the backups as well, but that is a slightly more complicated case there [in makepkg].

Is it? It looks like the exact same case there.

  1. What about this?
backup_package_variables() {
	restore_package_variables=$(declare -p "${splitpkg_overrides[@]}" 2>/dev/null || true)
}

restore_package_variables() {
	unset "${splitpkg_overrides[@]}"
	eval "$restore_package_variables"
}

@eli-schwartz eli-schwartz self-assigned this Mar 14, 2018
@@ -222,7 +222,7 @@ load ../lib/common

@test "package has to be aregular file" {
local p
local target=$(mktemp -d)
local target=$(mktemp -dt)
Copy link
Contributor

Choose a reason for hiding this comment

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

No TEMPLATE given, this change is extraneous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, you are correct.

@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 14, 2018

As I said on the mailing list, I don't see the need to overquote variables everywhere. You want it for the sake of linting (this is a shellcheck thing I actually disagree with) and to reduce the diff against your fork (which is not our design goal).

I'm not sure what to do about it.

I respect that. I'm not sure what I would do about it if I were in your place. If you want me to re-submit this patchset without the quoting commit, let me know.

@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from 795b654 to 5526570 Compare March 14, 2018 21:18
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 14, 2018

I've just pushed v3 of the patchset:

v3:

  • Use [[ $v = true ]] for testing boolean variables
  • Split the initial quoting commit in to a "only add double-quotes"
    commit and a commit with more involved changes
  • Combine the sort|uniq -> awk replacement commit with the more
    involved quoting commit
  • db-functions:check_pkgfile: Use [[ = ]] instead of [[ == ]]
  • Don't bother with mktemp's -t flag if there isn't a template given
  • Use declare -p to simplify {backup,restore}_package_variables
  • Use (( )) instead of [[ ]] when checking if an array is empty

I believe it addresses all of Eli's concerns, though it still quotes variables (but not variable-used-as-a-command; we don't have those anymore). I would have never though that quoting variables would be a controversial change.

fi
done
unset "${splitpkg_overrides[@]}"
eval "$restore_package_variables"
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW: https://lists.archlinux.org/pipermail/pacman-dev/2018-March/022406.html

TBH this whole script seems somewhat convoluted. If anything I think I'd rather port check_packages.py to use pyalpm instead of ctypes, and makepkg --printsrcinfo + python-srcinfo rather than parse_pkgbuilds.sh

But then again, I don't think anyone still uses it...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree about it being convoluted.

Isn't your solution going to have declare -p spit things on stderr?

echo "$(bsdtar -xf "${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" -O)" | grep -qv ${pkgname}
if bsdtar -xf "${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" -O | grep ${pkgname} &>/dev/null; then
return 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

grep -v has been converted to if grep; then return 1

I understand why that has been done here, as AFAICT this used to always return successfully since there was always some line that did not contain ${pkgname} -- even if that line was %NAME% :D

Which means we weren't actually testing anything with checkRemovedPackageDB as we cannot actually get test failures.

That being said, this does need to be noted in a commit message.

I also think it would make more sense to check for a pkgname using bsdtar -tf whereas in the other change we need to use -xf in order to check a pkgfile. (I'm not positive why we need to check the pkgfile there either.)

testing2x Outdated
@@ -49,7 +49,7 @@ done
for pkgarch in ${ARCHES[@]}; do
repo_unlock ${TESTING_REPO} ${pkgarch}
done
for repo in ${STABLE_REPOS[@]}; do
for repo in "${STABLE_REPOS[@]}"; do
Copy link
Contributor

Choose a reason for hiding this comment

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

Added extra whitespace here, commit message says you are removing whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh. I wonder how I screwed that up. But I did remove whitespace further up in the commit!

db-functions Outdated
chgrp $group "${filesfile}" || error "Could not change group of %s to %s" "$filesfile" "$group"
chmod g+w "${dbfile}" || error "Could not set write permission for group %s to %s" "$group" "$dbfile"
chmod g+w "${dbfile}" || error "Could not set write permission for group %s to %s" "$group" "$dbfile"
chmod g+w "${filesfile}" || error "Could not set write permission for group %s to %s" "$group" "$filesfile"
Copy link
Contributor

Choose a reason for hiding this comment

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

You lined up one of these, but the other is still misaligned...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops. That line is 2 characters to the left because $group is unquoted--it gets quoted in the next commit. I missed that line as being part of lining up when I split it in to 2 commits.

pkgarch=${pkginfo[2]}
pkglicense=(${pkginfo[@]:3})

while read -r pkgbase pkgver pkgarch pkglicense; do
Copy link
Contributor

Choose a reason for hiding this comment

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

pkglicense is now a string, rather than an array. It would still work as both licenses are in the (unquoted) array element 0, but of course that is now quoted.

So this only works if there is exactly one license in play.

@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from 5526570 to 62c3daa Compare March 16, 2018 02:34
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 16, 2018

I've just pushed v4 of the patchset

v4:

  • db-functions: fix lining up (relied on a change in a later commit)
  • testing2x: fix whitespace being introduced
  • parse_pkgbuilds.sh: have backup_package_variables output an
    expression; remove restore_package_variables
  • sourceballs: pkglicense should be an array
  • test/: have a test fixture have multiple entries in license=()
  • Note in the commit message that the grep -q commit fixes an issue
    by avoiding grep -v.

I believe this addresses each of Eli's comments. I did not switch to using bsdtar tf--I agree that it probably makes sense, but that's new work for another day.

@LukeShu LukeShu mentioned this pull request Mar 16, 2018
@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from 62c3daa to ca1c034 Compare March 16, 2018 03:24
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 16, 2018

I've just pushed v5 of this patchset. It's just rebasing on to
master.

v5:

  • Rewrite printf-formatter commit message, since most of this commit
    was subsumed by 33aae31.
  • Fix the ${pkgs[@]@Q} mistake in Misc touchup #6 as part of the
    fixups-near-quoting commit.

@LukeShu LukeShu closed this Mar 16, 2018
@LukeShu LukeShu deleted the lukeshu/rebase/archlinux+cleanup branch March 16, 2018 03:32
@LukeShu LukeShu restored the lukeshu/rebase/archlinux+cleanup branch March 16, 2018 03:32
@LukeShu LukeShu reopened this Mar 16, 2018
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 16, 2018

(whoops, deleted the wrong branch)

@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from ca1c034 to e683a64 Compare March 16, 2018 04:30
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 16, 2018

v6:

  • rebase, shuffle things affecting arch_repo_modify between commits

git diff between v5 and v6 comes up empty.

@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from e683a64 to f5774e4 Compare March 16, 2018 20:55
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 16, 2018

v7:

  • I had missed $_lockblock being used as a boolean/command in db-functions

@eli-schwartz
Copy link
Contributor

Was looking at replacing the whole parse_pkgbuild.sh mess with python-srcinfo and a custom srcinfo generator, but then got sidetracked and had to debug this: https://lists.archlinux.org/pipermail/pacman-dev/2018-March/022428.html

yay...

db-functions Outdated
}

getpkgfiles() {
local f files
if [[ ! -z "$(echo ${@%\.*} | sed "s/ /\n/g" | sort | uniq -D)" ]]; then
if ! printf '%s\n' "${@%\.*}" | awk 'a[$0]++>1{exit 1}'; then
Copy link
Contributor

Choose a reason for hiding this comment

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

My initial suggestion did not have >1 in it, and this version does not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aww crap, you're right. I added that when fixing the Travis failure the first night I submitted it ([comment] [build-log]). In my sleepy state I was thinking ++a[$0], and when Travis came back clean in the morning, I didn't think about it again.

@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from f5774e4 to b351f03 Compare March 20, 2018 05:14
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 20, 2018

v8:

  • db-functions: getpkgfiles: fix awk expression to detect duplicates
  • test/: add a test to verify that getpkgfiles() rejects duplicates

@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from b351f03 to 5a6c4dd Compare March 22, 2018 01:53
@LukeShu
Copy link
Contributor Author

LukeShu commented Mar 22, 2018

v9:

  • rebase

I think you should at least pick the test/ commit, but I wouldn't be upset if you wanted to reject the others.

@eli-schwartz
Copy link
Contributor

(Apologies for my initial response to the quoting changes, I did sort of overreact when I saw it breaking things due to excessive quoting. But that appears to be solved now, and it doesn't look like any other regressions are hiding.)

The rest look okay, I think. But I'm slightly confused what the test/ commit does, it seems to overlap the test case right above it?

Also apologies for the lateness of the response, since I'm now on holiday and somewhat erratically available.

@LukeShu LukeShu force-pushed the lukeshu/rebase/archlinux+cleanup branch from 5a6c4dd to eb09efd Compare April 3, 2018 01:38
@LukeShu
Copy link
Contributor Author

LukeShu commented Apr 3, 2018

The test above it checks that we detect when a package in $STAGING duplicates a package already in the repos. The new test checks that we detect duplicates when both packages are in $STAGING.

v10:

  • clean rebase, no changes

…same transaction

This is a leftover change from the patch that became 0432cff; v2 of that
patch broke db-functions:getpkgfiles, but the testsuite didn't catch it.
This patch adds a testcase that catches this type of breakage.
Search for unquoted variables using the command:

    grep -Prn --exclude-dir=.git '(?<!["=]|\[\[ |\[\[ -[zn] )\$(?!{?#|\(|\? )'

and ignore a bunch of false positives.

You may verify that the only differences between the lines removed and
lines added are double-quotes:

        diff -u \
          <(git show|sed -n 's/^-//p'|grep -v '^-- a/'|sed 's/"//g') \
          <(git show|sed -n 's/^+//p'|grep -v '^++ b/'|sed 's/"//g')
This does correct handling of
 - executing a program by symlink
 - any weird characters in the full path
 - I'm sure there's another case I thought about when I originally did
   this.
@eli-schwartz eli-schwartz force-pushed the lukeshu/rebase/archlinux+cleanup branch from eb09efd to 656fd6d Compare April 9, 2018 01:31
@eli-schwartz
Copy link
Contributor

v11: remove veverything comments from commit messages

@eli-schwartz eli-schwartz merged commit 656fd6d into archlinux:master Apr 9, 2018
@LukeShu LukeShu deleted the lukeshu/rebase/archlinux+cleanup branch April 10, 2018 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants