Skip to content

Commit

Permalink
A bit of reorganization in C/shell code.
Browse files Browse the repository at this point in the history
With these changes:
 - Added 'sanitize-plist' action to xbps-pkgdb. It takes a plist
   file as argument and writes another one "sanitized" by proplib.
   Use it to sanitize the pkgindex plist file.
 - Split xbps-pkgdb functions to be shared by other files.
 - Split xbps-digest functions to be shared by other files.
 - Rename the plist file to register/unregister installed pkgs to
   regpkgdb.plist, and related stuff in shell scripts.

--HG--
extra : convert_revision : 37731b04c6b41aebac629dfa06106175b9b5e59c
  • Loading branch information
Juan RP committed Dec 19, 2008
1 parent 5f69948 commit 48b2f03
Show file tree
Hide file tree
Showing 13 changed files with 834 additions and 586 deletions.
26 changes: 19 additions & 7 deletions utils/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
CFLAGS += -Wall -Werror -O3 -funroll-all-loops -ftree-loop-linear
PREFIX ?= /usr/local
PKGDB_CFLAGS += -Wall -Werror -I$(PREFIX)/include
PKGDB_LDFLAGS += -lprop
CFLAGS += -Wall -Werror -O3 -I$(PREFIX)/include
CFLAGS += -funroll-all-loops -ftree-loop-linear
LDFLAGS += -lprop

all: xbps-digest xbps-pkgdb xbps-cmpver clean_objs
all: xbps_digest xbps_pkgdb xbps-cmpver clean_objs

xbps-cmpver: xbps-cmpver.o
$(CC) $(CFLAGS) $< -o $@

sha256_digest: sha256_digest.o
$(CC) $(CFLAGS) -c $@

xbps-digest: xbps-digest.o
$(CC) $(CFLAGS) $< -o $@
$(CC) $(CFLAGS) -c $@

xbps_digest: xbps-digest.o sha256_digest.o
$(CC) $(LDFLAGS) -o xbps-digest xbps-digest.o sha256_digest.o

xbps-pkgdb:
$(CC) $(CFLAGS) -c $@

plist_utils:
$(CC) $(CFLAGS) -c $@

xbps-pkgdb: xbps-pkgdb.o
$(CC) $(PKGDB_CFLAGS) $(CFLAGS) $(PKGDB_LDFLAGS) $< -o $@
xbps_pkgdb: xbps-pkgdb.o plist_utils.o
$(CC) $(LDFLAGS) -o xbps-pkgdb xbps-pkgdb.o plist_utils.o

clean_objs:
-rm -f *.o
Expand Down
130 changes: 130 additions & 0 deletions utils/plist_utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*-
* Copyright (c) 2008 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <prop/proplib.h>

#include "plist_utils.h"

prop_dictionary_t
xbps_find_pkg_in_dict(prop_dictionary_t dict, const char *key,
const char *pkgname)
{
prop_array_t array;
prop_object_iterator_t iter;
prop_object_t obj;
const char *dpkgn;

if (dict == NULL || pkgname == NULL || key == NULL)
return NULL;

array = prop_dictionary_get(dict, key);
if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY)
return NULL;

iter = prop_array_iterator(array);
if (iter == NULL)
return NULL;

while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &dpkgn);
if (strcmp(dpkgn, pkgname) == 0)
break;
}
prop_object_iterator_release(iter);

return obj;
}

bool
xbps_add_obj_to_array(prop_array_t array, prop_object_t obj)
{
if (array == NULL || obj == NULL)
return false;

if (!prop_array_add(array, obj)) {
prop_object_release(array);
return false;
}

prop_object_release(obj);
return true;
}

bool
xbps_add_array_to_dict(prop_dictionary_t dict, prop_array_t array,
const char *key)
{
if (dict == NULL || array == NULL || key == NULL)
return false;

if (!prop_dictionary_set(dict, key, array))
return false;

prop_object_release(array);
return true;
}

void
xbps_list_pkgs_in_dict(prop_dictionary_t dict, const char *key)
{
prop_array_t array;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname, *version, *short_desc;

if (dict == NULL || key == NULL) {
printf("%s: NULL dict/key\n", __func__);
exit(1);
}

array = prop_dictionary_get(dict, key);
if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY) {
printf("%s: NULL or incorrect array type\n", __func__);
exit(1);
}

iter = prop_array_iterator(array);
if (iter == NULL) {
printf("%s: NULL iter\n", __func__);
exit(1);
}

while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
prop_dictionary_get_cstring_nocopy(obj, "short_desc",
&short_desc);
if (pkgname && version && short_desc)
printf("%s (%s)\t%s\n", pkgname, version, short_desc);
}

prop_object_iterator_release(iter);
}
78 changes: 78 additions & 0 deletions utils/plist_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*-
* Copyright (c) 2008 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _XBPS_PLIST_UTILS_H_
#define _XBPS_PLIST_UTILS_H_

/*
* Adds an array object with specified key into a dictionary.
*
* Arguments:
* - prop_dictionary_t: dictionary to store the array.
* - prop_array_t: the array to be stored.
* - const char *: the key associated with the array.
*
* Returns true on success, false on failure.
*/
bool
xbps_add_array_to_dict(prop_dictionary_t, prop_array_t, const char *);

/*
* Adds an opaque object into an array.
*
* Arguments:
* - prop_array_t: the array storing the object.
* - prop_object_t: the opaque object to be stored.
*
* Returns true on success, false on failure.
*/
bool
xbps_add_obj_to_array(prop_array_t, prop_object_t);

/*
* Finds a package's dictionary into the main dictionary.
*
* Arguments:
* - prop_dictionary_t: main dictionary to search the object.
* - 1st const char *key: use a dictionary with that key.
* - 2nd const char *pkgname: string of package name.
*
* Returns the package's dictionary object, otherwise NULL.
*/
prop_dictionary_t
xbps_find_pkg_in_dict(prop_dictionary_t, const char *, const char *);

/*
* Lists information about all packages found in a dictionary, by
* using a triplet: pkgname, version and short_desc.
*
* Arguments:
* - prop_dictionary_t: dictionary where to search on.
* - const char *: the key associated with the dictionary.
*/
void
xbps_list_pkgs_in_dict(prop_dictionary_t, const char *);

#endif /* !_XBPS_PLIST_UTILS_H_ */
38 changes: 10 additions & 28 deletions utils/sh/binpkg-genindex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ write_repo_pkgindex()

write_repo_pkgindex_footer $pkgindexf
if [ $? -eq 0 ]; then
$XBPS_REGPKGDB_CMD sanitize-plist $pkgindexf
[ $? -ne 0 ] && rm -f $pkgindexf && rm -rf $tmppkgdir && exit 1
msg_normal "Package index created (total pkgs: $pkgsum)."
cp -f $pkgindexf $XBPS_PACKAGESDIR/pkg-index.plist
fi
Expand All @@ -92,8 +94,8 @@ write_repo_pkgindex_header()
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>xbps_available_packages</key>
<array>
<key>xbps_available_packages</key>
<array>
_EOF
}

Expand All @@ -104,7 +106,7 @@ write_repo_pkgindex_footer()
[ -z "$file" ] && return 1

cat >> $file <<_EOF
</array>
</array>
</dict>
</plist>
_EOF
Expand All @@ -121,7 +123,6 @@ write_repo_pkgindex_dict()
local indexf="$2"
local binpkgf="$3"
local first_dict=
local array_found=
local tmpdictf=

[ -z "$pkgf" -o -z "$indexf" -o -z "$binpkgf" ] && return 1
Expand All @@ -132,40 +133,21 @@ write_repo_pkgindex_dict()
# Find the first dictionary.
if $(echo $line|grep -q "<dict>"); then
first_dict=yes
printf "\t\t$line\n" >> $tmpdictf
echo "$line" >> $tmpdictf
# Write the binary pkg filename before.
printf "\t\t\t<key>filename</key>\n" >> $tmpdictf
printf "\t\t\t<string>$binpkgf</string>\n" >> $tmpdictf
echo "<key>filename</key>" >> $tmpdictf
echo "<string>$binpkgf</string>" >> $tmpdictf
continue
# Continue until found.
elif [ -z "$first_dict" ]; then
continue
# Is this line the end of dictionary?
elif $(echo $line|grep -q "</dict>"); then
# It is.
printf "\t\t$line\n" >> $tmpdictf
echo "$line" >> $tmpdictf
break
# Is this line the start of an array?
elif $(echo $line|grep -q "<array>"); then
# It is.
array_found=yes
printf "\t\t\t$line\n" >> $tmpdictf
continue
# Is this line the end of array?
elif $(echo $line|grep -q "</array>"); then
# It is.
printf "\t\t\t$line\n" >> $tmpdictf
unset array_found
continue
# Print objects inside the dictionary.
elif [ -n "$array_found" ]; then
# Objects in arrays need an additional tab.
printf "\t\t\t\t$line\n" >> $tmpdictf
continue
else
# Normal indentation.
printf "\t\t\t$line\n" >> $tmpdictf
continue
echo "$line" >> $tmpdictf
fi
done

Expand Down
6 changes: 3 additions & 3 deletions utils/sh/builddep_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ install_dependencies_pkg()
msg_normal "Required minimal deps for $(basename $pkg):"
for i in ${installed_deps_list}; do
ipkg=${i%-[0-9]*.*}
iversion="$($XBPS_PKGDB_CMD version $ipkg)"
iversion="$($XBPS_REGPKGDB_CMD version $ipkg)"
echo " $ipkg >= ${i##[aA-zZ]*-}: found $ipkg-$iversion."
done

Expand Down Expand Up @@ -198,14 +198,14 @@ check_installed_pkg()
local reqver="$2"
local iver=

[ -z "$pkg" -o -z "$reqver" -o ! -r $XBPS_PKGDB_FPATH ] && return 1
[ -z "$pkg" -o -z "$reqver" -o ! -r $XBPS_REGPKGDB_PATH ] && return 1

if [ "$pkgname" != "${pkg%-[0-9]*.*}" ]; then
reset_tmpl_vars
. $XBPS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl
fi

iver="$($XBPS_PKGDB_CMD version $pkgname)"
iver="$($XBPS_REGPKGDB_CMD version $pkgname)"
if [ -n "$iver" ]; then
$XBPS_CMPVER_CMD $pkgname-$iver $pkgname-$reqver
[ $? -eq 0 ] && return 0
Expand Down
4 changes: 2 additions & 2 deletions utils/sh/pkgtarget_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ list_pkg_files()

[ -z $pkg ] && msg_error "unexistent package, aborting."

ver=$($XBPS_PKGDB_CMD version $pkg)
ver=$($XBPS_REGPKGDB_CMD version $pkg)
[ -z "$ver" ] && msg_error "$pkg is not installed."

cat $XBPS_PKGMETADIR/$pkg/flist
Expand All @@ -149,7 +149,7 @@ remove_pkg()

. $XBPS_TEMPLATESDIR/$pkg.tmpl

ver=$($XBPS_PKGDB_CMD version $pkg)
ver=$($XBPS_REGPKGDB_CMD version $pkg)
[ -z "$ver" ] && msg_error "$pkg is not installed."

if [ ! -d "$XBPS_DESTDIR/$pkg-$ver" ]; then
Expand Down
Loading

0 comments on commit 48b2f03

Please sign in to comment.