From ed62be888cdab0c84d4dd2799f8e4727cfaaf9d6 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jun 2019 16:38:17 -0400 Subject: [PATCH] Fix --completion-* args to work from AppImage (fixes #285) --- .gitignore | 1 + ChangeLog | 3 +++ README-maintainer | 14 +++++--------- azure-pipelines/build-appimage | 9 ++++++++- manual/qpdf-manual.xml | 7 +++++++ qpdf/qpdf.cc | 17 +++++++++++++++-- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 5c7f7fed..d938c24c 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ manual/print.xsl qpdf/build/ zlib-flate/build/ fuzz/qpdf_fuzzer_seed_corpus/ +distribution/ diff --git a/ChangeLog b/ChangeLog index b8e5ba3e..a7f9ba35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2019-06-22 Jay Berkenbilt + * It now works to run --completion-bash and --completion-zsh when + qpdf is started from an AppImage. + * Provided a more useful error message when Windows can't get security context. Thanks to user zdenop for supplying some code. Fixes #286. diff --git a/README-maintainer b/README-maintainer index 87c6f20a..93124ab8 100644 --- a/README-maintainer +++ b/README-maintainer @@ -264,15 +264,11 @@ zip -r qpdf-external-libs-src.zip external-libs When releasing on sourceforge, `external-libs` distributions go in `external-libs/yyyymmdd`, and qpdf distributions go in `qpdf/vvv`. -For local iteration on the AppImage generation, follow the release -procedures for building the AppImage, but instead of passing git clone -options to the docker command, copy qpdf to /tmp/build. You can also -pass -e SKIP_TESTS=1 to docker to skip the test suite, useful for -rapid iteration. Set up /tmp/build as in the release process. - -cp -a $PWD /tmp/build -docker run --privileged -ti --rm -e SKIP_TESTS=1 -v /tmp/build:/tmp/build qpdfbuild - +For local iteration on the AppImage generation, it works to just +./azure-pipelines/build-appimage and get the resulting AppImage from +the distribution directory. You can also pass -e SKIP_TESTS=1 +build-appimage, which passes it along to to docker, to skip the test +suite, which useful for rapid iteration. GENERAL BUILD STUFF diff --git a/azure-pipelines/build-appimage b/azure-pipelines/build-appimage index b3a99baa..8a614701 100755 --- a/azure-pipelines/build-appimage +++ b/azure-pipelines/build-appimage @@ -1,4 +1,9 @@ #!/bin/bash +# +# Any extra args are passed to the docker run command before the +# invocation of qpdfbuild. This is useful for iterating locally as +# described in README-maintainer. +# set -ex cd appimage docker build -t qpdfbuild . @@ -6,7 +11,9 @@ rm -rf build mkdir build cd .. git clone .git appimage/build/qpdf -docker run --privileged --rm -v $PWD/appimage/build:/tmp/build qpdfbuild +docker run --privileged --rm \ + -v $PWD/appimage/build:/tmp/build ${1+"$@"} qpdfbuild +rm -rf distribution mkdir distribution cp -p appimage/build/qpdf/appimage/build/qpdf*AppImage* distribution for i in distribution/*; do diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index 10af2c9b..b64b2b3b 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -4337,6 +4337,13 @@ print "\n"; with exit code 3 instead of 2. + + + The and + options now work properly + when qpdf is invoked as an AppImage. + + diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 01dec0fc..8f83317b 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -1471,10 +1471,23 @@ ArgParser::argHelp() void ArgParser::argCompletionBash() { + std::string progname = argv[0]; + // Detect if we're in an AppImage and adjust + std::string appdir; + std::string appimage; + if (QUtil::get_env("APPDIR", &appdir) && + QUtil::get_env("APPIMAGE", &appimage)) + { + if ((appdir.length() < strlen(argv[0])) && + (strncmp(appdir.c_str(), argv[0], appdir.length()) == 0)) + { + progname = appimage; + } + } std::cout << "complete -o bashdefault -o default -o nospace" - << " -C " << argv[0] << " " << whoami << std::endl; + << " -C " << progname << " " << whoami << std::endl; // Put output before error so calling from zsh works properly - std::string path = argv[0]; + std::string path = progname; size_t slash = path.find('/'); if ((slash != 0) && (slash != std::string::npos)) {