[pacman-dev] [PATCH] Add a timestamp file into repo tarballs

2019-11-05 Thread Allan McRae
When creating or modifying repo tarballs, place a .TIMESTAMP file with
seconds since epoch in it.  This will be used in the future to enable
rejecting databases older that a given threshold.

Also skip reading the .TIMESTAMP file in sync_db_populate().

Signed-off-by: Allan McRae 
---

Anyone want to check my logic in the sync_db_populate() populate change?
Repo-add puts the .TIMESTAMP file first when calling bsdtar, so if present
it will be first in the repo db file.  Otherwise the first item read from
the tarball will be a directory, which we skip reading anyway.  So I just
read the header for the first item and discard it.

 lib/libalpm/be_sync.c  | 9 +
 scripts/repo-add.sh.in | 8 +---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 2c76fe83..041b2266 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -506,6 +506,13 @@ static int sync_db_populate(alpm_db_t *db)
goto cleanup;
}
 
+   /* the .TIMESTAMP file will be first entry in the repo archive if 
present.
+* If not, the first entry will be a directory and can be skipped too */
+   if((archive_ret = archive_read_next_header(archive, &entry)) != 
ARCHIVE_OK) {
+   ret = -1;
+   goto readfail;
+   }
+
while((archive_ret = archive_read_next_header(archive, &entry)) == 
ARCHIVE_OK) {
mode_t mode = archive_entry_mode(entry);
if(!S_ISDIR(mode)) {
@@ -518,6 +525,8 @@ static int sync_db_populate(alpm_db_t *db)
}
}
}
+
+readfail:
if(archive_ret != ARCHIVE_EOF) {
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not read db '%s' 
(%s)\n"),
db->treename, archive_error_string(archive));
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index caf1232d..c87409f1 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -526,6 +526,7 @@ create_db() {
TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
# $LOCKFILE is already guaranteed to be absolute so this is safe
dirname=${LOCKFILE%/*}
+   timestamp=$(date +%s)
 
for repo in "db" "files"; do
filename=${REPO_DB_PREFIX}.${repo}.${REPO_DB_SUFFIX}
@@ -533,12 +534,13 @@ create_db() {
tempname=$dirname/.tmp.$filename
 
pushd "$tmpdir/$repo" >/dev/null
+   echo $timestamp > .TIMESTAMP
if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then
-   bsdtar -c ${TAR_OPT} -f "$tempname" *
+   bsdtar -c ${TAR_OPT} -f "$tempname" .TIMESTAMP *
else
-   # we have no packages remaining? zip up some emptyness
+   # we have no packages remaining
warning "$(gettext "No packages remain, creating empty 
database.")"
-   bsdtar -c ${TAR_OPT} -f "$tempname" -T /dev/null
+   bsdtar -c ${TAR_OPT} -f "$tempname" .TIMESTAMP
fi
popd >/dev/null
 
-- 
2.23.0


Re: [pacman-dev] [PATCH] Add a timestamp file into repo tarballs

2019-11-05 Thread Morten Linderud
On Tue, Nov 05, 2019 at 11:54:34PM +1000, Allan McRae wrote:
> When creating or modifying repo tarballs, place a .TIMESTAMP file with
> seconds since epoch in it.  This will be used in the future to enable
> rejecting databases older that a given threshold.
> 
> Also skip reading the .TIMESTAMP file in sync_db_populate().
> 
> Signed-off-by: Allan McRae 
> ---
> 
> Anyone want to check my logic in the sync_db_populate() populate change?
> Repo-add puts the .TIMESTAMP file first when calling bsdtar, so if present
> it will be first in the repo db file.  Otherwise the first item read from
> the tarball will be a directory, which we skip reading anyway.  So I just
> read the header for the first item and discard it.
> 
>  lib/libalpm/be_sync.c  | 9 +
>  scripts/repo-add.sh.in | 8 +---
>  2 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
> index 2c76fe83..041b2266 100644
> --- a/lib/libalpm/be_sync.c
> +++ b/lib/libalpm/be_sync.c
> @@ -506,6 +506,13 @@ static int sync_db_populate(alpm_db_t *db)
>   goto cleanup;
>   }
>  
> + /* the .TIMESTAMP file will be first entry in the repo archive if 
> present.
> +  * If not, the first entry will be a directory and can be skipped too */
> + if((archive_ret = archive_read_next_header(archive, &entry)) != 
> ARCHIVE_OK) {
> + ret = -1;
> + goto readfail;
> + }
> +
>   while((archive_ret = archive_read_next_header(archive, &entry)) == 
> ARCHIVE_OK) {
>   mode_t mode = archive_entry_mode(entry);
>   if(!S_ISDIR(mode)) {
> @@ -518,6 +525,8 @@ static int sync_db_populate(alpm_db_t *db)
>   }
>   }
>   }
> +
> +readfail:
>   if(archive_ret != ARCHIVE_EOF) {
>   _alpm_log(db->handle, ALPM_LOG_ERROR, _("could not read db '%s' 
> (%s)\n"),
>   db->treename, archive_error_string(archive));
> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> index caf1232d..c87409f1 100644
> --- a/scripts/repo-add.sh.in
> +++ b/scripts/repo-add.sh.in
> @@ -526,6 +526,7 @@ create_db() {
>   TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
>   # $LOCKFILE is already guaranteed to be absolute so this is safe
>   dirname=${LOCKFILE%/*}
> + timestamp=$(date +%s)

This should probably utilize SOURCE_DATE_EPOCH or something equivalent?

timestamp=$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%s))

>   for repo in "db" "files"; do
>   filename=${REPO_DB_PREFIX}.${repo}.${REPO_DB_SUFFIX}
> @@ -533,12 +534,13 @@ create_db() {
>   tempname=$dirname/.tmp.$filename
>  
>   pushd "$tmpdir/$repo" >/dev/null
> + echo $timestamp > .TIMESTAMP
>   if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then
> - bsdtar -c ${TAR_OPT} -f "$tempname" *
> + bsdtar -c ${TAR_OPT} -f "$tempname" .TIMESTAMP *
>   else
> - # we have no packages remaining? zip up some emptyness
> + # we have no packages remaining
>   warning "$(gettext "No packages remain, creating empty 
> database.")"
> - bsdtar -c ${TAR_OPT} -f "$tempname" -T /dev/null
> + bsdtar -c ${TAR_OPT} -f "$tempname" .TIMESTAMP
>   fi
>   popd >/dev/null
>  
> -- 
> 2.23.0

-- 
Morten Linderud
PGP: 9C02FF419FECBE16


signature.asc
Description: PGP signature


Re: [pacman-dev] [PATCH] Add a timestamp file into repo tarballs

2019-11-05 Thread Allan McRae
On 5/11/19 11:58 pm, Morten Linderud wrote:
> On Tue, Nov 05, 2019 at 11:54:34PM +1000, Allan McRae wrote:
>> When creating or modifying repo tarballs, place a .TIMESTAMP file with
>> seconds since epoch in it.  This will be used in the future to enable
>> rejecting databases older that a given threshold.
>>
>> Also skip reading the .TIMESTAMP file in sync_db_populate().
>>
>> Signed-off-by: Allan McRae 
>> ---
>>



>> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
>> index caf1232d..c87409f1 100644
>> --- a/scripts/repo-add.sh.in
>> +++ b/scripts/repo-add.sh.in
>> @@ -526,6 +526,7 @@ create_db() {
>>  TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
>>  # $LOCKFILE is already guaranteed to be absolute so this is safe
>>  dirname=${LOCKFILE%/*}
>> +timestamp=$(date +%s)
> 
> This should probably utilize SOURCE_DATE_EPOCH or something equivalent?
> 
> timestamp=$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%s))

Why?  I can see no reason why it should...


Re: [pacman-dev] [PATCH] Add a timestamp file into repo tarballs

2019-11-05 Thread Eli Schwartz
On 11/5/19 9:03 AM, Allan McRae wrote:
> On 5/11/19 11:58 pm, Morten Linderud wrote:
>> On Tue, Nov 05, 2019 at 11:54:34PM +1000, Allan McRae wrote:
>>> When creating or modifying repo tarballs, place a .TIMESTAMP file with
>>> seconds since epoch in it.  This will be used in the future to enable
>>> rejecting databases older that a given threshold.
>>>
>>> Also skip reading the .TIMESTAMP file in sync_db_populate().
>>>
>>> Signed-off-by: Allan McRae 
>>> ---
>>>
> 
> 
> 
>>> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
>>> index caf1232d..c87409f1 100644
>>> --- a/scripts/repo-add.sh.in
>>> +++ b/scripts/repo-add.sh.in
>>> @@ -526,6 +526,7 @@ create_db() {
>>> TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
>>> # $LOCKFILE is already guaranteed to be absolute so this is safe
>>> dirname=${LOCKFILE%/*}
>>> +   timestamp=$(date +%s)
>>
>> This should probably utilize SOURCE_DATE_EPOCH or something equivalent?
>>
>> timestamp=$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%s))
> 
> Why?  I can see no reason why it should...

I don't either see value in "reproducible builds" for the actual state
of the database. It's just a series of plaintext pointers to some other
(hopefully reproducible) packages.

If we actually did want to respect SOURCE_DATE_EPOCH, we'd need to do a
lot more, like doing that for the bsdtar metadata (both file timestamps
and file owners, probably sort files too, etc.) but again, I don't see
how this protects the supply chain.

-- 
Eli Schwartz
Bug Wrangler and Trusted User



signature.asc
Description: OpenPGP digital signature


Re: [pacman-dev] [PATCH] Add a timestamp file into repo tarballs

2019-11-05 Thread Morten Linderud
On Wed, Nov 06, 2019 at 12:03:17AM +1000, Allan McRae wrote:
> On 5/11/19 11:58 pm, Morten Linderud wrote:
> > On Tue, Nov 05, 2019 at 11:54:34PM +1000, Allan McRae wrote:
> >> When creating or modifying repo tarballs, place a .TIMESTAMP file with
> >> seconds since epoch in it.  This will be used in the future to enable
> >> rejecting databases older that a given threshold.
> >>
> >> Also skip reading the .TIMESTAMP file in sync_db_populate().
> >>
> >> Signed-off-by: Allan McRae 
> >> ---
> >>
> 
> 
> 
> >> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> >> index caf1232d..c87409f1 100644
> >> --- a/scripts/repo-add.sh.in
> >> +++ b/scripts/repo-add.sh.in
> >> @@ -526,6 +526,7 @@ create_db() {
> >>TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
> >># $LOCKFILE is already guaranteed to be absolute so this is safe
> >>dirname=${LOCKFILE%/*}
> >> +  timestamp=$(date +%s)
> > 
> > This should probably utilize SOURCE_DATE_EPOCH or something equivalent?
> > 
> > timestamp=$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%s))
> 
> Why?  I can see no reason why it should...

If you wan't to write tests for `repo-add` in the future, I think it will be
beneficial to be able to create consistent databases.

Outside of pacman I believe being able to reproduce any artifact produced is
desireable. Enables us to not run through hoops recreating past database files
given the correct packages.

-- 
Morten Linderud
PGP: 9C02FF419FECBE16


signature.asc
Description: PGP signature


Re: [pacman-dev] [PATCH] Add a timestamp file into repo tarballs

2019-11-05 Thread Morten Linderud
On Tue, Nov 05, 2019 at 09:12:33AM -0500, Eli Schwartz wrote:
> On 11/5/19 9:03 AM, Allan McRae wrote:
> > On 5/11/19 11:58 pm, Morten Linderud wrote:
> >> On Tue, Nov 05, 2019 at 11:54:34PM +1000, Allan McRae wrote:
> >>> When creating or modifying repo tarballs, place a .TIMESTAMP file with
> >>> seconds since epoch in it.  This will be used in the future to enable
> >>> rejecting databases older that a given threshold.
> >>>
> >>> Also skip reading the .TIMESTAMP file in sync_db_populate().
> >>>
> >>> Signed-off-by: Allan McRae 
> >>> ---
> >>>
> > 
> > 
> > 
> >>> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> >>> index caf1232d..c87409f1 100644
> >>> --- a/scripts/repo-add.sh.in
> >>> +++ b/scripts/repo-add.sh.in
> >>> @@ -526,6 +526,7 @@ create_db() {
> >>>   TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
> >>>   # $LOCKFILE is already guaranteed to be absolute so this is safe
> >>>   dirname=${LOCKFILE%/*}
> >>> + timestamp=$(date +%s)
> >>
> >> This should probably utilize SOURCE_DATE_EPOCH or something equivalent?
> >>
> >> timestamp=$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%s))
> > 
> > Why?  I can see no reason why it should...
> 
> I don't either see value in "reproducible builds" for the actual state
> of the database. It's just a series of plaintext pointers to some other
> (hopefully reproducible) packages.
> 
> If we actually did want to respect SOURCE_DATE_EPOCH, we'd need to do a
> lot more, like doing that for the bsdtar metadata (both file timestamps
> and file owners, probably sort files too, etc.) but again, I don't see
> how this protects the supply chain.

Hmm, should probably discuss the threat model or attack vectors in
#archlinux-reproducible.

-- 
Morten Linderud
PGP: 9C02FF419FECBE16


signature.asc
Description: PGP signature


[pacman-dev] [PATCH] pacman: clarify error when alpm fails to init

2019-11-05 Thread morganamilo
Currently pacman is hard coded to print the dbpath, then the error alpm
returned. Even though the error could really be caused by anything.

So instead just print the arugemnts given to alpm and not assume the
resulting error message is releated to either path.

Fixes FS#59595

Signed-off-by: morganamilo 

diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 468a3e02..42946189 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -766,8 +766,8 @@ static int setup_libalpm(void)
/* initialize library */
handle = alpm_initialize(config->rootdir, config->dbpath, &err);
if(!handle) {
-   pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm 
library\n(%s: %s)\n"),
-   alpm_strerror(err), config->dbpath);
+   pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm library 
(root: %s, dbpath: %s):\n%s\n"),
+   config->rootdir, config->dbpath, alpm_strerror(err));
if(err == ALPM_ERR_DB_VERSION) {
fprintf(stderr, _("try running pacman-db-upgrade\n"));
}
-- 
2.23.0


[pacman-dev] [PATCH] makepkg: replace sed in-place with built-in substitution

2019-11-05 Thread Ethan Sommer
Read PKGBUILD into an array and replace the pkgver and pkgrel with
bash parameter substitution, then use shell redirection to write to to
the file. Because shell redirection follows symlinks, this accomplishes
the same thing as the previous default of using the GNU-specific
--follow-symlinks sed flag.

Remove SEDPATH and SEDINPLACEFLAGS from the build systems as they are
not used elsewhere.
---
 build-aux/edit-script.sh.in |  2 --
 configure.ac| 11 ---
 meson.build | 11 ---
 meson_options.txt   |  3 ---
 scripts/Makefile.am |  2 --
 scripts/makepkg.sh.in   |  7 ---
 6 files changed, 4 insertions(+), 32 deletions(-)

diff --git a/build-aux/edit-script.sh.in b/build-aux/edit-script.sh.in
index 640d32f8..7423a223 100644
--- a/build-aux/edit-script.sh.in
+++ b/build-aux/edit-script.sh.in
@@ -20,8 +20,6 @@ mode=$3
   -e "s|@DEBUGSUFFIX[@]|@DEBUGSUFFIX@|g" \
   -e "s|@INODECMD[@]|@INODECMD@|g" \
   -e "s|@FILECMD[@]|@FILECMD@|g" \
-  -e "s|@SEDINPLACEFLAGS[@]|@SEDINPLACEFLAGS@|g" \
-  -e "s|@SEDPATH[@]|@SEDPATH@|g" \
   -e "s|@configure_input[@]|Generated from ${input##*/}; do not edit by 
hand.|g" \
   "$input" >"$output"
 
diff --git a/configure.ac b/configure.ac
index 305432b3..e59f82e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -369,7 +369,6 @@ AC_CHECK_MEMBERS([struct statfs.f_flags],,,[[#include 

 GCC_VISIBILITY_CC
 
 # Host-dependant definitions
-DEFAULT_SEDINPLACEFLAGS=" --follow-symlinks -i"
 INODECMD="stat -c '%i %n'"
 STRIP_BINARIES="--strip-all"
 STRIP_SHARED="--strip-unneeded"
@@ -377,30 +376,21 @@ STRIP_STATIC="--strip-debug"
 case "${host_os}" in
*bsd*)
INODECMD="stat -f '%i %N'"
-   DEFAULT_SEDINPLACEFLAGS=" -i \"\""
;;
darwin*)
host_os_darwin=yes
INODECMD="/usr/bin/stat -f '%i %N'"
-   DEFAULT_SEDINPLACEFLAGS=" -i ''"
STRIP_BINARIES=""
STRIP_SHARED="-S"
STRIP_STATIC="-S"
;;
 esac
 AM_CONDITIONAL([DARWIN], test "x$host_os_darwin" = "xyes")
-AC_PATH_PROGS([SEDPATH], [sed], [sed], [/usr/bin$PATH_SEPARATOR/bin] )
 AC_SUBST(INODECMD)
 AC_SUBST(STRIP_BINARIES)
 AC_SUBST(STRIP_SHARED)
 AC_SUBST(STRIP_STATIC)
 
-# Flags for sed in place
-if test "${SEDINPLACEFLAGS+set}" != "set"; then
-SEDINPLACEFLAGS="${DEFAULT_SEDINPLACEFLAGS}"
-fi
-AC_ARG_VAR(SEDINPLACEFLAGS, [flags for sed, overriding the default])
-
 # Variables plugged into makepkg.conf
 CARCH="${host%%-*}"
 CHOST="${host}"
@@ -576,7 +566,6 @@ ${PACKAGE_NAME}:
 Architecture   : ${CARCH}
 Host Type  : ${CHOST}
 File inode command : ${INODECMD}
-In-place sed command   : ${SEDPATH} ${SEDINPLACEFLAGS}
 File seccomp command   : ${FILECMD}
 
 libalpm version: ${LIB_VERSION}
diff --git a/meson.build b/meson.build
index 8c296cb8..36f87ed2 100644
--- a/meson.build
+++ b/meson.build
@@ -221,7 +221,6 @@ config_h = configure_file(
 add_project_arguments('-include', 'config.h', language : 'c')
 
 filecmd = 'file'
-default_sedinplaceflags = ' --follow-symlinks -i'
 inodecmd = 'stat -c \'%i %n\''
 strip_binaries = '--strip-all'
 strip_shared = '--strip-unneeded'
@@ -237,18 +236,11 @@ endif
 os = host_machine.system()
 if os.startswith('darwin')
   inodecmd = '/usr/bin/stat -f \'%i %N\''
-  default_sedinplaceflags = ' -i \'\''
   strip_binaries = ''
   strip_shared = '-s'
   strip_static = '-s'
 elif os.contains('bsd') or os == 'dragonfly'
   inodecmd = 'stat -f \'%i %N\''
-  default_sedinplaceflags = ' -i \'\''
-endif
-
-sedinplaceflags = get_option('sedinplaceflags')
-if sedinplaceflags == 'auto'
-  sedinplaceflags = default_sedinplaceflags
 endif
 
 chost = run_command(cc, '-dumpmachine').stdout().strip()
@@ -277,8 +269,6 @@ substs.set('TEMPLATE_DIR', 
get_option('makepkg-template-dir'))
 substs.set('DEBUGSUFFIX', get_option('debug-suffix'))
 substs.set('INODECMD', inodecmd)
 substs.set('FILECMD', filecmd)
-substs.set('SEDINPLACEFLAGS', sedinplaceflags)
-substs.set('SEDPATH', SED.path())
 substs.set('LIBMAKEPKGDIR', LIBMAKEPKGDIR)
 substs.set('STRIP_BINARIES', strip_binaries)
 substs.set('STRIP_SHARED', strip_shared)
@@ -430,7 +420,6 @@ message('\n'.join([
   '   Architecture: @0@'.format(carch),
   '   Host Type   : @0@'.format(chost),
   '   File inode command  : @0@'.format(inodecmd),
-  '   In-place sed command: @0@ @1@'.format(SED.path(), sedinplaceflags),
   '   File seccomp command: @0@'.format(filecmd),
   '   libalpm version : @0@'.format(libalpm_version),
   '   pacman version  : @0@'.format(PACKAGE_VERSION),
diff --git a/meson_options.txt b/meson_options.txt
index 2b92ca1a..4d8cc300 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -54,6 +54,3 @@ option('i18n', type : 'boolean', value : true,
 # tools
 option('file-seccomp', type: 'feature', value: 'auto',
   description: 'deter

[pacman-dev] [PATCH] pacman: make exact_file an int

2019-11-05 Thread morganamilo
We only ever use it as a bool, no need to pass a char* around.

Signed-off-by: morganamilo 

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 19191dd8..3b6dc23b 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -58,7 +58,7 @@ static void print_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, 
char *filename)
alpm_pkg_get_version(pkg), colstr->nocolor);
 }
 
-static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg, 
char *exact_file)
+static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg, 
int exact_file)
 {
alpm_db_t *db_local = alpm_get_localdb(config->handle);
const colstr_t *colstr = &config->colstr;
@@ -71,7 +71,7 @@ static void print_match(alpm_list_t *match, alpm_db_t *repo, 
alpm_pkg_t *pkg, ch
}
} else if(config->quiet) {
printf("%s/%s\n", alpm_db_get_name(repo), 
alpm_pkg_get_name(pkg));
-   } else if(exact_file != NULL) {
+   } else if(exact_file) {
alpm_list_t *ml;
for(ml = match; ml; ml = alpm_list_next(ml)) {
char *filename = ml->data;
@@ -104,9 +104,9 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
int found = 0;
regex_t reg;
size_t len = strlen(targ);
-   char *exact_file = strchr(targ, '/');
+   int exact_file = strchr(targ, '/') != NULL;
 
-   if(exact_file != NULL) {
+   if(exact_file) {
while(len > 1 && targ[0] == '/') {
targ++;
len--;
@@ -131,7 +131,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
alpm_list_t *match = NULL;
 
-   if(exact_file != NULL) {
+   if(exact_file) {
if (regex) {
for(size_t f = 0; f < 
files->count; f++) {
char *c = 
files->files[f].name;
-- 
2.23.0


Re: [pacman-dev] [PATCH] pacman: clarify error when alpm fails to init

2019-11-05 Thread Allan McRae
On 6/11/19 9:08 am, morganamilo wrote:
> Currently pacman is hard coded to print the dbpath, then the error alpm
> returned. Even though the error could really be caused by anything.
> 
> So instead just print the arugemnts given to alpm and not assume the
> resulting error message is releated to either path.
> 
> Fixes FS#59595
> 
> Signed-off-by: morganamilo 
> 
> diff --git a/src/pacman/conf.c b/src/pacman/conf.c
> index 468a3e02..42946189 100644
> --- a/src/pacman/conf.c
> +++ b/src/pacman/conf.c
> @@ -766,8 +766,8 @@ static int setup_libalpm(void)
>   /* initialize library */
>   handle = alpm_initialize(config->rootdir, config->dbpath, &err);
>   if(!handle) {
> - pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm 
> library\n(%s: %s)\n"),
> - alpm_strerror(err), config->dbpath);
> + pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm library 
> (root: %s, dbpath: %s):\n%s\n"),

Added a newline before the two directories and applied.

A

> + config->rootdir, config->dbpath, alpm_strerror(err));
>   if(err == ALPM_ERR_DB_VERSION) {
>   fprintf(stderr, _("try running pacman-db-upgrade\n"));
>   }
> 


Re: [pacman-dev] [PATCH] makepkg: replace sed in-place with built-in substitution

2019-11-05 Thread Allan McRae
On 6/11/19 10:18 am, Ethan Sommer wrote:
> Read PKGBUILD into an array and replace the pkgver and pkgrel with
> bash parameter substitution, then use shell redirection to write to to
> the file. Because shell redirection follows symlinks, this accomplishes
> the same thing as the previous default of using the GNU-specific
> --follow-symlinks sed flag.
> 
> Remove SEDPATH and SEDINPLACEFLAGS from the build systems as they are
> not used elsewhere.
> ---

I like the idea, but am concerned about unintended consequences...

I saw the following mentioned on IRC:
- potential for changed line endings
- added newline at the end of files without one
- removing any null characters

I'm leaning on the side of these being fine, but need to mull on it some
more.

Anything else I missed?



> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
> index c49ac57a..b9e83458 100644
> --- a/scripts/makepkg.sh.in
> +++ b/scripts/makepkg.sh.in
> @@ -199,13 +199,14 @@ update_pkgver() {
>   fi
>  
>   if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
> - if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
> - if ! @SEDPATH@ @SEDINPLACEFLAGS@ "s:^pkgver=[^ 
> ]*:pkgver=$newpkgver:" "$BUILDFILE"; then
> + if [[ -w $BUILDFILE ]]; then
> + mapfile -t buildfile < "$BUILDFILE"
> + buildfile=("${buildfile[@]/#pkgver=*([^ 
> ])/pkgver=$newpkgver}")
> + if ! printf '%s\n' "${buildfile[@]/#pkgrel=*([^ 
> ])/pkgrel=1}" > "$BUILDFILE"; then

split into two lines:

buildfile=("${buildfile[@]/#pkgrel=*([^ ])/pkgrel=1}")
if ! print '%s\n" "${buildfile[@]}"...

>   error "$(gettext "Failed to update %s from %s 
> to %s")" \
>   "pkgver" "$pkgver" "$newpkgver"
>   exit $E_PKGBUILD_ERROR
>   fi
> - @SEDPATH@ @SEDINPLACEFLAGS@ "s:^pkgrel=[^ ]*:pkgrel=1:" 
> "$BUILDFILE"
>   source_safe "$BUILDFILE"
>   local fullver=$(get_full_version)
>   msg "$(gettext "Updated version: %s")" "$pkgbase 
> $fullver"
> 


Re: [pacman-dev] [PATCH] makepkg: replace sed in-place with built-in substitution

2019-11-05 Thread Eli Schwartz
On 11/5/19 8:18 PM, Allan McRae wrote:
> On 6/11/19 10:18 am, Ethan Sommer wrote:
>> Read PKGBUILD into an array and replace the pkgver and pkgrel with
>> bash parameter substitution, then use shell redirection to write to to
>> the file. Because shell redirection follows symlinks, this accomplishes
>> the same thing as the previous default of using the GNU-specific
>> --follow-symlinks sed flag.
>>
>> Remove SEDPATH and SEDINPLACEFLAGS from the build systems as they are
>> not used elsewhere.
>> ---
> 
> I like the idea, but am concerned about unintended consequences...
> 
> I saw the following mentioned on IRC:
> - potential for changed line endings

You mean essentially dos2unix? The PKGBUILD would not be valid bash if
it had the wrong type of line endings, bash would attempt to read lots
of $'\r' as actual commands and stuff. That being said, a $'\r' in an
embedded string could break, I suppose.

> - added newline at the end of files without one

I would actually like to force people to have newlines at the end of
their bash files. :(

> - removing any null characters

(I don't actually expect those to exist. The PKGBUILD would have to be
read by something other than makepkg, the only use case offhand I can
think of for embedded null characters in a shell script is those foo.run
installer things which extract a tarball archive from the end of the
script file and then exit before hitting the appended tarball data.)

> I'm leaning on the side of these being fine, but need to mull on it some
> more.
As long as we don't care about embedded $'\r' in string data I *think*
we should be fine.

-- 
Eli Schwartz
Bug Wrangler and Trusted User



signature.asc
Description: OpenPGP digital signature


[pacman-dev] [PATCH v2] makepkg: replaces sed in-place with built in substitution

2019-11-05 Thread Ethan Sommer
Reads PKGBUILD into an array and replaces the pkgver and pkgrel with
bash parameter substitution, then uses shell redirection to write to to
the file. Because shell redirection follows symlinks, this accomplishes
the same thing as the previous default of using the GNU-specific
--follow-symlinks sed flag.

Removes SEDPATH and SEDINPLACEFLAGS from the build systems as they are
not used elsewhere.

Signed-off-by: Ethan Sommer 
---
 build-aux/edit-script.sh.in |  2 --
 configure.ac| 11 ---
 meson.build | 11 ---
 meson_options.txt   |  3 ---
 scripts/Makefile.am |  2 --
 scripts/makepkg.sh.in   |  8 +---
 6 files changed, 5 insertions(+), 32 deletions(-)

diff --git a/build-aux/edit-script.sh.in b/build-aux/edit-script.sh.in
index 640d32f8..7423a223 100644
--- a/build-aux/edit-script.sh.in
+++ b/build-aux/edit-script.sh.in
@@ -20,8 +20,6 @@ mode=$3
   -e "s|@DEBUGSUFFIX[@]|@DEBUGSUFFIX@|g" \
   -e "s|@INODECMD[@]|@INODECMD@|g" \
   -e "s|@FILECMD[@]|@FILECMD@|g" \
-  -e "s|@SEDINPLACEFLAGS[@]|@SEDINPLACEFLAGS@|g" \
-  -e "s|@SEDPATH[@]|@SEDPATH@|g" \
   -e "s|@configure_input[@]|Generated from ${input##*/}; do not edit by 
hand.|g" \
   "$input" >"$output"
 
diff --git a/configure.ac b/configure.ac
index 305432b3..e59f82e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -369,7 +369,6 @@ AC_CHECK_MEMBERS([struct statfs.f_flags],,,[[#include 

 GCC_VISIBILITY_CC
 
 # Host-dependant definitions
-DEFAULT_SEDINPLACEFLAGS=" --follow-symlinks -i"
 INODECMD="stat -c '%i %n'"
 STRIP_BINARIES="--strip-all"
 STRIP_SHARED="--strip-unneeded"
@@ -377,30 +376,21 @@ STRIP_STATIC="--strip-debug"
 case "${host_os}" in
*bsd*)
INODECMD="stat -f '%i %N'"
-   DEFAULT_SEDINPLACEFLAGS=" -i \"\""
;;
darwin*)
host_os_darwin=yes
INODECMD="/usr/bin/stat -f '%i %N'"
-   DEFAULT_SEDINPLACEFLAGS=" -i ''"
STRIP_BINARIES=""
STRIP_SHARED="-S"
STRIP_STATIC="-S"
;;
 esac
 AM_CONDITIONAL([DARWIN], test "x$host_os_darwin" = "xyes")
-AC_PATH_PROGS([SEDPATH], [sed], [sed], [/usr/bin$PATH_SEPARATOR/bin] )
 AC_SUBST(INODECMD)
 AC_SUBST(STRIP_BINARIES)
 AC_SUBST(STRIP_SHARED)
 AC_SUBST(STRIP_STATIC)
 
-# Flags for sed in place
-if test "${SEDINPLACEFLAGS+set}" != "set"; then
-SEDINPLACEFLAGS="${DEFAULT_SEDINPLACEFLAGS}"
-fi
-AC_ARG_VAR(SEDINPLACEFLAGS, [flags for sed, overriding the default])
-
 # Variables plugged into makepkg.conf
 CARCH="${host%%-*}"
 CHOST="${host}"
@@ -576,7 +566,6 @@ ${PACKAGE_NAME}:
 Architecture   : ${CARCH}
 Host Type  : ${CHOST}
 File inode command : ${INODECMD}
-In-place sed command   : ${SEDPATH} ${SEDINPLACEFLAGS}
 File seccomp command   : ${FILECMD}
 
 libalpm version: ${LIB_VERSION}
diff --git a/meson.build b/meson.build
index 8c296cb8..36f87ed2 100644
--- a/meson.build
+++ b/meson.build
@@ -221,7 +221,6 @@ config_h = configure_file(
 add_project_arguments('-include', 'config.h', language : 'c')
 
 filecmd = 'file'
-default_sedinplaceflags = ' --follow-symlinks -i'
 inodecmd = 'stat -c \'%i %n\''
 strip_binaries = '--strip-all'
 strip_shared = '--strip-unneeded'
@@ -237,18 +236,11 @@ endif
 os = host_machine.system()
 if os.startswith('darwin')
   inodecmd = '/usr/bin/stat -f \'%i %N\''
-  default_sedinplaceflags = ' -i \'\''
   strip_binaries = ''
   strip_shared = '-s'
   strip_static = '-s'
 elif os.contains('bsd') or os == 'dragonfly'
   inodecmd = 'stat -f \'%i %N\''
-  default_sedinplaceflags = ' -i \'\''
-endif
-
-sedinplaceflags = get_option('sedinplaceflags')
-if sedinplaceflags == 'auto'
-  sedinplaceflags = default_sedinplaceflags
 endif
 
 chost = run_command(cc, '-dumpmachine').stdout().strip()
@@ -277,8 +269,6 @@ substs.set('TEMPLATE_DIR', 
get_option('makepkg-template-dir'))
 substs.set('DEBUGSUFFIX', get_option('debug-suffix'))
 substs.set('INODECMD', inodecmd)
 substs.set('FILECMD', filecmd)
-substs.set('SEDINPLACEFLAGS', sedinplaceflags)
-substs.set('SEDPATH', SED.path())
 substs.set('LIBMAKEPKGDIR', LIBMAKEPKGDIR)
 substs.set('STRIP_BINARIES', strip_binaries)
 substs.set('STRIP_SHARED', strip_shared)
@@ -430,7 +420,6 @@ message('\n'.join([
   '   Architecture: @0@'.format(carch),
   '   Host Type   : @0@'.format(chost),
   '   File inode command  : @0@'.format(inodecmd),
-  '   In-place sed command: @0@ @1@'.format(SED.path(), sedinplaceflags),
   '   File seccomp command: @0@'.format(filecmd),
   '   libalpm version : @0@'.format(libalpm_version),
   '   pacman version  : @0@'.format(PACKAGE_VERSION),
diff --git a/meson_options.txt b/meson_options.txt
index 2b92ca1a..4d8cc300 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -54,6 +54,3 @@ option('i18n', type : 'boolean', value : true,
 # tools
 option('file-seccomp', type: 'feature', value: 'au

Re: [pacman-dev] [PATCH] makepkg: replace sed in-place with built-in substitution

2019-11-05 Thread Eli Schwartz
On 11/5/19 8:28 PM, Eli Schwartz wrote:
> On 11/5/19 8:18 PM, Allan McRae wrote:
>> On 6/11/19 10:18 am, Ethan Sommer wrote:
>>> Read PKGBUILD into an array and replace the pkgver and pkgrel with
>>> bash parameter substitution, then use shell redirection to write to to
>>> the file. Because shell redirection follows symlinks, this accomplishes
>>> the same thing as the previous default of using the GNU-specific
>>> --follow-symlinks sed flag.
>>>
>>> Remove SEDPATH and SEDINPLACEFLAGS from the build systems as they are
>>> not used elsewhere.
>>> ---
>>
>> I like the idea, but am concerned about unintended consequences...
>>
>> I saw the following mentioned on IRC:
>> - potential for changed line endings
> 
> You mean essentially dos2unix? The PKGBUILD would not be valid bash if
> it had the wrong type of line endings, bash would attempt to read lots
> of $'\r' as actual commands and stuff. That being said, a $'\r' in an
> embedded string could break, I suppose.

Turns out we even check for this.

if [[ $(<"$BUILDFILE") = *$'\r'* ]]; then
error "$(gettext "%s contains %s characters and cannot
be sourced.")" "$BUILDFILE" "CRLF"


-- 
Eli Schwartz
Bug Wrangler and Trusted User



signature.asc
Description: OpenPGP digital signature


[pacman-dev] [PATCH] pacman+libalpm: handle search errors

2019-11-05 Thread morganamilo
Previously, pacman treated no matches and an error during search the
same.

To fix this, alpm_db_search now returns its status as an int and
instead takes the to be returned list as a param. Allowing front ends to
easily differentiate between errors and no matches.

Signed-off-by: morganamilo 

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 4486da44..d3630385 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -997,9 +997,11 @@ alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db);
 /** Searches a database with regular expressions.
  * @param db pointer to the package database to search in
  * @param needles a list of regular expressions to search for
- * @return the list of packages matching all regular expressions on success, 
NULL on error
+ * @param ret the list of packages matching all regular expressions
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
  */
-alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
+int alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
+   alpm_list_t **ret);
 
 typedef enum _alpm_db_usage_t {
ALPM_DB_USAGE_SYNC = 1,
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index a443e552..cf4c865f 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -298,12 +298,14 @@ alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t 
*db)
 }
 
 /** Searches a database. */
-alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t 
*needles)
+int SYMEXPORT alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
+   alpm_list_t **ret)
 {
-   ASSERT(db != NULL, return NULL);
+   ASSERT(db != NULL && ret != NULL && *ret == NULL,
+   RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
db->handle->pm_errno = ALPM_ERR_OK;
 
-   return _alpm_db_search(db, needles);
+   return _alpm_db_search(db, needles, ret);
 }
 
 /** Sets the usage bitmask for a repo */
@@ -396,13 +398,13 @@ int _alpm_db_cmp(const void *d1, const void *d2)
return strcmp(db1->treename, db2->treename);
 }
 
-alpm_list_t *_alpm_db_search(alpm_db_t *db, const alpm_list_t *needles)
+int _alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
+   alpm_list_t **ret)
 {
const alpm_list_t *i, *j, *k;
-   alpm_list_t *ret = NULL;
 
if(!(db->usage & ALPM_DB_USAGE_SEARCH)) {
-   return NULL;
+   return 0;
}
 
/* copy the pkgcache- we will free the list var after each needle */
@@ -415,12 +417,12 @@ alpm_list_t *_alpm_db_search(alpm_db_t *db, const 
alpm_list_t *needles)
if(i->data == NULL) {
continue;
}
-   ret = NULL;
+   *ret = NULL;
targ = i->data;
_alpm_log(db->handle, ALPM_LOG_DEBUG, "searching for target 
'%s'\n", targ);
 
if(regcomp(®, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | 
REG_NEWLINE) != 0) {
-   RET_ERR(db->handle, ALPM_ERR_INVALID_REGEX, NULL);
+   RET_ERR(db->handle, ALPM_ERR_INVALID_REGEX, -1);
}
 
for(j = list; j; j = j->next) {
@@ -463,18 +465,18 @@ alpm_list_t *_alpm_db_search(alpm_db_t *db, const 
alpm_list_t *needles)
_alpm_log(db->handle, ALPM_LOG_DEBUG,
"search target '%s' matched 
'%s' on package '%s'\n",
targ, matched, name);
-   ret = alpm_list_add(ret, pkg);
+   *ret = alpm_list_add(*ret, pkg);
}
}
 
/* Free the existing search list, and use the returned list for 
the
 * next needle. This allows for AND-based package searching. */
alpm_list_free(list);
-   list = ret;
+   list = *ret;
regfree(®);
}
 
-   return ret;
+   return 0;
 }
 
 /* Returns a new package cache from db.
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index f17444e6..e7ad98f5 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -87,7 +87,8 @@ alpm_db_t *_alpm_db_new(const char *treename, int is_local);
 void _alpm_db_free(alpm_db_t *db);
 const char *_alpm_db_path(alpm_db_t *db);
 int _alpm_db_cmp(const void *d1, const void *d2);
-alpm_list_t *_alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
+int _alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
+   alpm_list_t **ret);
 alpm_db_t *_alpm_db_register_local(alpm_handle_t *handle);
 alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename,
int level);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 35cfcd94..ec6e78fc 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -518,12 +518,13 @@ void print_groups(alpm_pkg_t *pkg)
  * @param db the databas

[pacman-dev] [PATCH] pacman: print error message for -F with invalid regex

2019-11-05 Thread morganamilo


diff --git a/src/pacman/files.c b/src/pacman/files.c
index 19191dd8..05b6f223 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -115,7 +115,8 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
 
if(regex) {
if(regcomp(®, targ, REG_EXTENDED | REG_NOSUB | 
REG_ICASE | REG_NEWLINE) != 0) {
-   /* TODO: error message */
+   pm_printf(ALPM_LOG_ERROR,
+   _("search failed: invalid 
regular expression '%s'\n"), targ);
goto notfound;
}
}
-- 
2.23.0


[pacman-dev] [GIT] The official pacman repository branch, master, updated. v5.2.1-7-g3a814ee6

2019-11-05 Thread Allan McRae
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The official pacman repository".

The branch, master has been updated
   via  3a814ee6bca9ee24a868c0dc032b321048a53e08 (commit)
   via  424129e8d1e91987a9799a49391f1271b069c5cf (commit)
   via  27955a0fee16f817b5569e0bc29bc1498a87ea68 (commit)
  from  1bfae7d14a7bdad777e82912c5c6883deb11aee5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -
commit 3a814ee6bca9ee24a868c0dc032b321048a53e08
Author: Ethan Sommer 
Date:   Tue Nov 5 20:29:11 2019 -0500

makepkg: replaces sed in-place with built in substitution

Reads PKGBUILD into an array and replaces the pkgver and pkgrel with
bash parameter substitution, then uses shell redirection to write to to
the file. Because shell redirection follows symlinks, this accomplishes
the same thing as the previous default of using the GNU-specific
--follow-symlinks sed flag.

Removes SEDPATH and SEDINPLACEFLAGS from the build systems as they are
not used elsewhere.

Signed-off-by: Ethan Sommer 
Signed-off-by: Allan McRae 

commit 424129e8d1e91987a9799a49391f1271b069c5cf
Author: morganamilo 
Date:   Tue Nov 5 23:08:26 2019 +

pacman: clarify error when alpm fails to init

Currently pacman is hard coded to print the dbpath, then the error alpm
returned. Even though the error could really be caused by anything.

So instead just print the arugemnts given to alpm and not assume the
resulting error message is releated to either path.

Fixes FS#59595

Signed-off-by: morganamilo 
Signed-off-by: Allan McRae 

commit 27955a0fee16f817b5569e0bc29bc1498a87ea68
Author: Allan McRae 
Date:   Tue Nov 5 15:25:52 2019 +1000

Move update-copyright into build-aux

This is a useful function to update all our copyright years. Move
it into build-aux so that it is not lost in the switch to meson.

Signed-off-by: Allan McRae 

---

Summary of changes:
 Makefile.am |  7 +--
 build-aux/edit-script.sh.in |  2 --
 build-aux/update-copyright  |  8 
 configure.ac| 11 ---
 meson.build | 11 ---
 meson_options.txt   |  3 ---
 scripts/Makefile.am |  2 --
 scripts/makepkg.sh.in   |  8 +---
 src/pacman/conf.c   |  4 ++--
 9 files changed, 16 insertions(+), 40 deletions(-)
 create mode 100755 build-aux/update-copyright


hooks/post-receive
-- 
The official pacman repository


Re: [pacman-dev] [PATCH] pacman+libalpm: handle search errors

2019-11-05 Thread Morgan Adamiec
On Wed, 6 Nov 2019 at 01:44, morganamilo  wrote:
>
> Previously, pacman treated no matches and an error during search the
> same.
>
> To fix this, alpm_db_search now returns its status as an int and
> instead takes the to be returned list as a param. Allowing front ends to
> easily differentiate between errors and no matches.
>
> Signed-off-by: morganamilo 
>
> diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
> index 4486da44..d3630385 100644
> --- a/lib/libalpm/alpm.h
> +++ b/lib/libalpm/alpm.h
> @@ -997,9 +997,11 @@ alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db);
>  /** Searches a database with regular expressions.
>   * @param db pointer to the package database to search in
>   * @param needles a list of regular expressions to search for
> - * @return the list of packages matching all regular expressions on success, 
> NULL on error
> + * @param ret the list of packages matching all regular expressions
> + * @return 0 on success, -1 on error (pm_errno is set accordingly)
>   */
> -alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
> +int alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
> +   alpm_list_t **ret);
>
>  typedef enum _alpm_db_usage_t {
> ALPM_DB_USAGE_SYNC = 1,
> diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
> index a443e552..cf4c865f 100644
> --- a/lib/libalpm/db.c
> +++ b/lib/libalpm/db.c
> @@ -298,12 +298,14 @@ alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t 
> *db)
>  }
>
>  /** Searches a database. */
> -alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t 
> *needles)
> +int SYMEXPORT alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
> +   alpm_list_t **ret)
>  {
> -   ASSERT(db != NULL, return NULL);
> +   ASSERT(db != NULL && ret != NULL && *ret == NULL,
> +   RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
> db->handle->pm_errno = ALPM_ERR_OK;
>
> -   return _alpm_db_search(db, needles);
> +   return _alpm_db_search(db, needles, ret);
>  }
>
>  /** Sets the usage bitmask for a repo */
> @@ -396,13 +398,13 @@ int _alpm_db_cmp(const void *d1, const void *d2)
> return strcmp(db1->treename, db2->treename);
>  }
>
> -alpm_list_t *_alpm_db_search(alpm_db_t *db, const alpm_list_t *needles)
> +int _alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
> +   alpm_list_t **ret)
>  {
> const alpm_list_t *i, *j, *k;
> -   alpm_list_t *ret = NULL;
>
> if(!(db->usage & ALPM_DB_USAGE_SEARCH)) {
> -   return NULL;
> +   return 0;
> }
>
> /* copy the pkgcache- we will free the list var after each needle */
> @@ -415,12 +417,12 @@ alpm_list_t *_alpm_db_search(alpm_db_t *db, const 
> alpm_list_t *needles)
> if(i->data == NULL) {
> continue;
> }
> -   ret = NULL;
> +   *ret = NULL;
> targ = i->data;
> _alpm_log(db->handle, ALPM_LOG_DEBUG, "searching for target 
> '%s'\n", targ);
>
> if(regcomp(®, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | 
> REG_NEWLINE) != 0) {
> -   RET_ERR(db->handle, ALPM_ERR_INVALID_REGEX, NULL);
> +   RET_ERR(db->handle, ALPM_ERR_INVALID_REGEX, -1);
> }
>
> for(j = list; j; j = j->next) {
> @@ -463,18 +465,18 @@ alpm_list_t *_alpm_db_search(alpm_db_t *db, const 
> alpm_list_t *needles)
> _alpm_log(db->handle, ALPM_LOG_DEBUG,
> "search target '%s' matched 
> '%s' on package '%s'\n",
> targ, matched, name);
> -   ret = alpm_list_add(ret, pkg);
> +   *ret = alpm_list_add(*ret, pkg);
> }
> }
>
> /* Free the existing search list, and use the returned list 
> for the
>  * next needle. This allows for AND-based package searching. 
> */
> alpm_list_free(list);
> -   list = ret;
> +   list = *ret;
> regfree(®);
> }
>
> -   return ret;
> +   return 0;
>  }
>
>  /* Returns a new package cache from db.
> diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
> index f17444e6..e7ad98f5 100644
> --- a/lib/libalpm/db.h
> +++ b/lib/libalpm/db.h
> @@ -87,7 +87,8 @@ alpm_db_t *_alpm_db_new(const char *treename, int is_local);
>  void _alpm_db_free(alpm_db_t *db);
>  const char *_alpm_db_path(alpm_db_t *db);
>  int _alpm_db_cmp(const void *d1, const void *d2);
> -alpm_list_t *_alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
> +int _alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
> +   alpm_list_t **ret);
>  alpm_db_t *_alpm_db_register_local(alpm_handle_t *handle);
>  alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle

[pacman-dev] [PATCH] scripts/library: remove human_to_size

2019-11-05 Thread Eli Schwartz
pkgdelta was the last user, and it is gone now.

Signed-off-by: Eli Schwartz 
---
 Makefile.am|  1 -
 scripts/Makefile.am|  4 ---
 scripts/library/README | 10 --
 scripts/library/human_to_size.sh   | 51 ---
 scripts/meson.build|  6 
 scripts/po/POTFILES.in |  1 -
 test/scripts/Makefile.am   |  3 +-
 test/scripts/human_to_size_test.sh | 55 --
 test/scripts/meson.build   |  1 -
 9 files changed, 1 insertion(+), 131 deletions(-)
 delete mode 100644 scripts/library/README
 delete mode 100644 scripts/library/human_to_size.sh
 delete mode 100755 test/scripts/human_to_size_test.sh

diff --git a/Makefile.am b/Makefile.am
index c661f447..8b8b6882 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,7 +35,6 @@ $(top_srcdir)/test/pacman/tests/TESTS: $(wildcard 
test/pacman/tests/*.py)
@printf "TESTS += %s\n" $^ | LC_ALL=C sort -u > "$@"
 
 TESTS =  test/scripts/parseopts_test.sh \
-test/scripts/human_to_size_test.sh \
 test/scripts/makepkg-template_test.sh \
 test/scripts/pacman-db-upgrade-v9.py \
 test/util/vercmptest.sh
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 63d09767..1a5f0a04 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -31,13 +31,9 @@ EXTRA_DIST = \
repo-add.sh.in \
wrapper.sh.in \
$(COMPLETION_DIST) \
-   $(LIBRARY) \
$(LIBMAKEPKG_DIST) \
po/meson.build
 
-LIBRARY = \
-   library/human_to_size.sh
-
 libmakepkgdir = $(datarootdir)/makepkg
 
 LIBMAKEPKGDIRS = \
diff --git a/scripts/library/README b/scripts/library/README
deleted file mode 100644
index d20f117a..
--- a/scripts/library/README
+++ /dev/null
@@ -1,10 +0,0 @@
-This directory contains code snippets that can be reused by multiple
-scripts.  A brief description of each file follows.
-
-human_to_size.sh:
-A function to convert human readable sizes (such as "5.3 GiB") to raw byte
-equivalents. base10 and base2 suffixes are supported, case sensitively. If
-successful, the converted byte value is written to stdout and the function
-returns 0. If an error occurs, nothing is written and the function returns 1.
-Results may be inaccurate when using a broken implementation of awk, such
-as mawk or busybox awk.
diff --git a/scripts/library/human_to_size.sh b/scripts/library/human_to_size.sh
deleted file mode 100644
index 11613207..
--- a/scripts/library/human_to_size.sh
+++ /dev/null
@@ -1,51 +0,0 @@
-human_to_size() {
-  awk -v human="$1" '
-  function trim(s) {
-gsub(/^[[:space:]]+|[[:space:]]+$/, "", s)
-return s
-  }
-
-  function parse_units(units) {
-if (!units || units == "B")
-  return 1
-if (match(units, /^.iB$/))
-  return 1024
-if (match(units, /^.B$/))
-  return 1000
-if (length(units) == 1)
-  return 1024
-
-# parse failure: invalid base
-return -1
-  }
-
-  function parse_scale(s) {
-return index("BKMGTPE", s) - 1
-  }
-
-  function isnumeric(string) {
-return match(string, /^[-+]?[[:digit:]]*(\.[[:digit:]]*)?/)
-  }
-
-  BEGIN {
-# peel off the leading number as the size, fail on invalid number
-human = trim(human)
-if (isnumeric(human))
-  size = substr(human, RSTART, RLENGTH)
-else
-  exit 1
-
-# the trimmed remainder is assumed to be the units
-units = trim(substr(human, RLENGTH + 1))
-
-base = parse_units(units)
-if (base < 0)
-  exit 1
-
-scale = parse_scale(substr(units, 1, 1))
-if (scale < 0)
-  exit 1
-
-printf "%d\n", size * base^scale + (size + 0 > 0 ? 0.5 : -0.5)
-  }'
-}
diff --git a/scripts/meson.build b/scripts/meson.build
index 7d533f35..56f31222 100644
--- a/scripts/meson.build
+++ b/scripts/meson.build
@@ -9,10 +9,6 @@ scripts = [
   'makepkg-template.pl.in',
 ]
 
-library_files = [
-  'library/human_to_size.sh',
-]
-
 SCRIPT_EDITOR = find_program(configure_file(
   input : join_paths(meson.source_root(), 'build-aux/edit-script.sh.in'),
   output : 'edit-script.sh',
@@ -32,7 +28,6 @@ foreach script : scripts
 input : m4_edit.process(script),
 command : [ SCRIPT_EDITOR, '@INPUT@', '@OUTPUT@', '0755'],
 output : script_shortname,
-depend_files : library_files,
 install : true,
 install_dir : get_option('bindir'))
 endforeach
@@ -48,7 +43,6 @@ foreach script : wrapped_scripts
 input : m4_edit.process(script),
 command : [ SCRIPT_EDITOR, '@INPUT@', '@OUTPUT@', '0755'],
 output : script,
-depend_files : library_files,
 build_by_default : true)
 
   cdata = configuration_data()
diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in
index 5f02393d..f7d8d93e 100644
--- a/scripts/po/POTFILES.in
+++ b/scripts/po/POTFILES.in
@@ -65,4 +65,3 @@ scripts/libmakepkg/util/parseopts.sh.in
 scripts/libma

[pacman-dev] [PATCH] build: remove use of handcrafted m4 in configuring scripts

2019-11-05 Thread Eli Schwartz
Now that library/ is fully gone, we don't need this anymore.

Signed-off-by: Eli Schwartz 
---

Followup to removing human_to_size.

 meson.build |  2 --
 scripts/Makefile.am |  2 +-
 scripts/meson.build | 10 ++
 3 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/meson.build b/meson.build
index 8c296cb8..33613db0 100644
--- a/meson.build
+++ b/meson.build
@@ -28,7 +28,6 @@ LIBMAKEPKGDIR = join_paths(PREFIX, DATAROOTDIR, 'makepkg')
 PKGDATADIR = join_paths(PREFIX, DATAROOTDIR, meson.project_name())
 
 PYTHON = import('python').find_installation('python3')
-M4 = find_program('m4')
 SED = find_program('sed')
 DU = find_program('du')
 LDCONFIG = get_option('ldconfig')
@@ -258,7 +257,6 @@ carch = chost.split('-')[0]
 # largely identical, but which distinguishes between quoting needs.
 substs = configuration_data()
 substs.set('SED', SED.path())
-substs.set('M4', M4.path())
 substs.set('CARCH', carch)
 substs.set('CHOST', chost)
 substs.set('PKGEXT', get_option('pkg-ext'))
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 1a5f0a04..735db752 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -192,7 +192,7 @@ edit = sed \
 ## wrong file by accident.
 $(OURSCRIPTS): %: %.sh.in wrapper.sh.in $(LIBMAKEPKG_IN) Makefile
$(AM_V_at)$(RM) $@
-   $(AM_V_GEN)test -f $(srcdir)/$@.sh.in && m4 -P -I $(srcdir) 
$(srcdir)/$@.sh.in | $(edit) >$@
+   $(AM_V_GEN)test -f $(srcdir)/$@.sh.in && $(edit) $(srcdir)/$@.sh.in >$@
$(AM_V_at)chmod +x,a-w $@
@$(BASH_SHELL) -O extglob -n $@
 
diff --git a/scripts/meson.build b/scripts/meson.build
index 56f31222..696d8ddd 100644
--- a/scripts/meson.build
+++ b/scripts/meson.build
@@ -14,18 +14,12 @@ SCRIPT_EDITOR = find_program(configure_file(
   output : 'edit-script.sh',
   configuration : substs))
 
-m4_edit = generator(
-  M4,
-  arguments : ['-P', '-I', meson.current_source_dir(), '@INPUT@'],
-  output : '@PLAINNAME@',
-  capture : true)
-
 foreach script : scripts
   script_shortname = script.split('.')[0]
 
   custom_target(
 script,
-input : m4_edit.process(script),
+input : script,
 command : [ SCRIPT_EDITOR, '@INPUT@', '@OUTPUT@', '0755'],
 output : script_shortname,
 install : true,
@@ -40,7 +34,7 @@ foreach script : wrapped_scripts
   # the build directory.
   internal_script = custom_target(
 script,
-input : m4_edit.process(script),
+input : script,
 command : [ SCRIPT_EDITOR, '@INPUT@', '@OUTPUT@', '0755'],
 output : script,
 build_by_default : true)
-- 
2.24.0


[pacman-dev] [PATCH] Remove "Generated from ...; do not edit by hand" from scripts

2019-11-05 Thread Allan McRae
This is a useless piece of information.

Signed-off-by: Allan McRae 
---
 build-aux/edit-script.sh.in | 1 -
 scripts/Makefile.am | 3 +--
 scripts/makepkg-template.pl.in  | 1 -
 scripts/makepkg.sh.in   | 1 -
 scripts/pacman-db-upgrade.sh.in | 1 -
 scripts/pacman-key.sh.in| 1 -
 scripts/repo-add.sh.in  | 1 -
 7 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/build-aux/edit-script.sh.in b/build-aux/edit-script.sh.in
index 7423a223..661c22d5 100644
--- a/build-aux/edit-script.sh.in
+++ b/build-aux/edit-script.sh.in
@@ -20,7 +20,6 @@ mode=$3
   -e "s|@DEBUGSUFFIX[@]|@DEBUGSUFFIX@|g" \
   -e "s|@INODECMD[@]|@INODECMD@|g" \
   -e "s|@FILECMD[@]|@FILECMD@|g" \
-  -e "s|@configure_input[@]|Generated from ${input##*/}; do not edit by 
hand.|g" \
   "$input" >"$output"
 
 if [[ $mode ]]; then
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 3cb6c133..191fc3d3 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -186,8 +186,7 @@ edit = sed \
-e 's|@DEBUGSUFFIX[@]|$(DEBUGSUFFIX)|g' \
-e "s|@INODECMD[@]|$(INODECMD)|g" \
-e "s|@FILECMD[@]|$(FILECMD)|g" \
-   -e 's|@SCRIPTNAME[@]|$@|g' \
-   -e 's|@configure_input[@]|Generated from $<; do not edit by hand.|g'
+   -e 's|@SCRIPTNAME[@]|$@|g'
 
 ## All the scripts depend on Makefile so that they are rebuilt when the
 ## prefix etc. changes. Use chmod -w to prevent people from editing the
diff --git a/scripts/makepkg-template.pl.in b/scripts/makepkg-template.pl.in
index da5eba1b..762dd4be 100755
--- a/scripts/makepkg-template.pl.in
+++ b/scripts/makepkg-template.pl.in
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 #   makepkg-template - template system for makepkg
-#   @configure_input@
 #
 #   Copyright (c) 2013-2019 Pacman Development Team 
 #
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 22df1b9f..2deb61da 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1,7 +1,6 @@
 #!/bin/bash
 #
 #   makepkg - make packages compatible for use with pacman
-#   @configure_input@
 #
 #   Copyright (c) 2006-2019 Pacman Development Team 
 #   Copyright (c) 2002-2006 by Judd Vinet 
diff --git a/scripts/pacman-db-upgrade.sh.in b/scripts/pacman-db-upgrade.sh.in
index 5d65bc88..4a904b6d 100644
--- a/scripts/pacman-db-upgrade.sh.in
+++ b/scripts/pacman-db-upgrade.sh.in
@@ -1,7 +1,6 @@
 #!/bin/bash -e
 #
 #   pacman-db-upgrade - upgrade the local pacman db to a newer format
-#   @configure_input@
 #
 #   Copyright (c) 2010-2019 Pacman Development Team 
 #
diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in
index 366fd205..613b3514 100644
--- a/scripts/pacman-key.sh.in
+++ b/scripts/pacman-key.sh.in
@@ -2,7 +2,6 @@
 #
 #   pacman-key - manages pacman's keyring
 #Based on apt-key, from Debian
-#   @configure_input@
 #
 #   Copyright (c) 2010-2019 Pacman Development Team 
 #
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index caf1232d..f7dd8948 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -2,7 +2,6 @@
 #
 #   repo-add - add a package to a given repo database file
 #   repo-remove - remove a package entry from a given repo database file
-#   @configure_input@
 #
 #   Copyright (c) 2006-2019 Pacman Development Team 
 #
-- 
2.23.0