mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
* Initial changes to gensync - makepkg changes were not checked in from another
machine - still pending * Addition of _alpm_pkg_makefilename to simplify the with/without -ARCH prefix scheme we're going with for the interim
This commit is contained in:
parent
74e780f25d
commit
00ce9ea739
@ -26,6 +26,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -705,6 +706,44 @@ int alpm_pkg_vercmp(const char *ver1, const char *ver2)
|
||||
return(_alpm_versioncmp(ver1, ver2));
|
||||
}
|
||||
|
||||
/* internal */
|
||||
char *_supported_archs[] = {
|
||||
"i586",
|
||||
"i686",
|
||||
"ppc",
|
||||
"x86_64",
|
||||
};
|
||||
|
||||
char *alpm_pkg_name_hasarch(char *pkgname)
|
||||
{
|
||||
/* TODO remove this when we transfer everything over to -ARCH
|
||||
*
|
||||
* this parsing sucks... it's done to support
|
||||
* two package formats for the time being:
|
||||
* package-name-foo-1.0.0-1-i686
|
||||
* and
|
||||
* package-name-bar-1.2.3-1
|
||||
*/
|
||||
int i = 0;
|
||||
char *arch, *cmp, *p;
|
||||
|
||||
if((p = strrchr(pkgname, '-'))) {
|
||||
for(i=0; i < sizeof(_supported_archs)/sizeof(char*); ++i) {
|
||||
cmp = p+1;
|
||||
arch = _supported_archs[i];
|
||||
|
||||
/* whee, case insensitive compare */
|
||||
|
||||
while(*arch && *cmp && tolower(*arch++) == tolower(*cmp++)) ;
|
||||
if(*arch || *cmp) continue;
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @defgroup alpm_groups Group Functions
|
||||
|
@ -205,6 +205,7 @@ int alpm_pkg_checksha1sum(PM_PKG *pkg);
|
||||
char *alpm_fetch_pkgurl(char *url);
|
||||
int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this_section);
|
||||
int alpm_pkg_vercmp(const char *ver1, const char *ver2);
|
||||
char *alpm_pkg_name_hasarch(char *pkgname);
|
||||
|
||||
/*
|
||||
* Groups
|
||||
|
@ -435,6 +435,30 @@ pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack)
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
char *_alpm_pkg_makefilename(pmpkg_t *pkg)
|
||||
{
|
||||
char *fname = NULL;
|
||||
int len = 0, arch_valid = 0;
|
||||
|
||||
len = strlen(pkg->name) + strlen(pkg->version) + strlen(PM_EXT_PKG) + 3;
|
||||
if(pkg->arch && strlen(pkg->arch) > 0) {
|
||||
arch_valid = 1;
|
||||
len += strlen(pkg->arch) + 1;
|
||||
}
|
||||
|
||||
if((fname = (char *)calloc(len, sizeof(char))) == NULL) {
|
||||
RET_ERR(PM_ERR_MEMORY, NULL);
|
||||
}
|
||||
|
||||
if(arch_valid) {
|
||||
snprintf(fname, len-1, "%s-%s-%s" PM_EXT_PKG, pkg->name, pkg->version, pkg->arch);
|
||||
} else {
|
||||
snprintf(fname, len-1, "%s-%s" PM_EXT_PKG, pkg->name, pkg->version);
|
||||
}
|
||||
|
||||
return fname;
|
||||
}
|
||||
|
||||
int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch)
|
||||
{
|
||||
char tmp[PKG_FULLNAME_LEN+7];
|
||||
@ -456,12 +480,9 @@ int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch)
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
if((p = _alpm_pkgname_has_arch(tmp))) {
|
||||
*p = '\0';
|
||||
}
|
||||
if(witharch) {
|
||||
/* trim architecture */
|
||||
if((p = _alpm_pkgname_has_arch(tmp))) {
|
||||
if((p = alpm_pkg_name_hasarch(tmp))) {
|
||||
*p = 0;
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ void _alpm_pkg_free(void *data);
|
||||
int _alpm_pkg_cmp(const void *p1, const void *p2);
|
||||
pmpkg_t *_alpm_pkg_load(char *pkgfile);
|
||||
pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack);
|
||||
char *_alpm_pkg_makefilename(pmpkg_t *pkg);
|
||||
int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch);
|
||||
|
||||
#endif /* _ALPM_PACKAGE_H */
|
||||
|
@ -180,6 +180,7 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
|
||||
} else {
|
||||
dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "" : "p"));
|
||||
}
|
||||
|
||||
if(downloadLastErrCode != 0 || dlf == NULL) {
|
||||
_alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s://%s: %s"), fn,
|
||||
server->s_url->scheme, server->s_url->host, downloadLastErrString);
|
||||
|
@ -785,23 +785,23 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data)
|
||||
pmdb_t *dbs = spkg->data;
|
||||
|
||||
if(current == dbs) {
|
||||
char *fname = NULL;
|
||||
char path[PATH_MAX];
|
||||
|
||||
fname = _alpm_pkg_makefilename(spkg);
|
||||
if(trans->flags & PM_TRANS_FLAG_PRINTURIS) {
|
||||
snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, spkg->name, spkg->version);
|
||||
EVENT(trans, PM_TRANS_EVT_PRINTURI, alpm_db_getinfo(current, PM_DB_FIRSTSERVER), path);
|
||||
EVENT(trans, PM_TRANS_EVT_PRINTURI, alpm_db_getinfo(current, PM_DB_FIRSTSERVER), fname);
|
||||
} else {
|
||||
struct stat buf;
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s" PM_EXT_PKG, ldir, spkg->name, spkg->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s", ldir, fname);
|
||||
if(stat(path, &buf)) {
|
||||
/* file is not in the cache dir, so add it to the list */
|
||||
snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, spkg->name, spkg->version);
|
||||
files = _alpm_list_add(files, strdup(path));
|
||||
files = _alpm_list_add(files, strdup(fname));
|
||||
} else {
|
||||
_alpm_log(PM_LOG_DEBUG, _("%s-%s%s is already in the cache\n"),
|
||||
spkg->name, spkg->version, PM_EXT_PKG);
|
||||
_alpm_log(PM_LOG_DEBUG, _("%s is already in the cache\n"), fname);
|
||||
}
|
||||
}
|
||||
FREE(fname);
|
||||
}
|
||||
}
|
||||
|
||||
@ -843,12 +843,11 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data)
|
||||
for(i = trans->packages; i; i = i->next) {
|
||||
pmsyncpkg_t *sync = i->data;
|
||||
pmpkg_t *spkg = sync->pkg;
|
||||
char str[PATH_MAX], pkgname[PATH_MAX];
|
||||
char str[PATH_MAX], *pkgname;
|
||||
char *md5sum1, *md5sum2, *sha1sum1, *sha1sum2;
|
||||
char *ptr=NULL;
|
||||
|
||||
snprintf(pkgname, PATH_MAX, "%s-%s" PM_EXT_PKG,
|
||||
spkg->name, spkg->version);
|
||||
pkgname = _alpm_pkg_makefilename(spkg);
|
||||
md5sum1 = spkg->md5sum;
|
||||
sha1sum1 = spkg->sha1sum;
|
||||
|
||||
@ -885,7 +884,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data)
|
||||
}
|
||||
if(doremove) {
|
||||
char str[PATH_MAX];
|
||||
snprintf(str, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG, handle->root, handle->cachedir, spkg->name, spkg->version);
|
||||
snprintf(str, PATH_MAX, "%s%s/%s", handle->root, handle->cachedir, pkgname);
|
||||
unlink(str);
|
||||
snprintf(ptr, 512, _("archive %s was corrupted (bad MD5 or SHA1 checksum)\n"), pkgname);
|
||||
} else {
|
||||
@ -894,6 +893,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data)
|
||||
*data = _alpm_list_add(*data, ptr);
|
||||
retval = 1;
|
||||
}
|
||||
FREE(pkgname);
|
||||
FREE(md5sum2);
|
||||
FREE(sha1sum2);
|
||||
}
|
||||
@ -965,8 +965,12 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data)
|
||||
for(i = trans->packages; i; i = i->next) {
|
||||
pmsyncpkg_t *sync = i->data;
|
||||
pmpkg_t *spkg = sync->pkg;
|
||||
|
||||
char *fname = NULL;
|
||||
char str[PATH_MAX];
|
||||
snprintf(str, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG, handle->root, handle->cachedir, spkg->name, spkg->version);
|
||||
|
||||
fname = _alpm_pkg_makefilename(spkg);
|
||||
snprintf(str, PATH_MAX, "%s%s/%s", handle->root, handle->cachedir, fname);
|
||||
if(_alpm_trans_addtarget(tr, str) == -1) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -641,44 +641,4 @@ void _alpm_time2string(time_t t, char *buffer)
|
||||
}
|
||||
}
|
||||
|
||||
/* internal */
|
||||
char *_supported_archs[] = {
|
||||
"i586",
|
||||
"i686",
|
||||
"ppc",
|
||||
"x86_64",
|
||||
};
|
||||
|
||||
char *_alpm_pkgname_has_arch(char *pkgname)
|
||||
{
|
||||
/* TODO remove this when we transfer everything over to -ARCH
|
||||
*
|
||||
* this parsing sucks... it's done to support
|
||||
* two package formats for the time being:
|
||||
* package-name-foo-1.0.0-1-i686
|
||||
* and
|
||||
* package-name-bar-1.2.3-1
|
||||
*/
|
||||
int i = 0;
|
||||
char *arch, *cmp, *p;
|
||||
|
||||
if((p = strrchr(pkgname, '-'))) {
|
||||
for(i=0; i < sizeof(_supported_archs)/sizeof(char*); ++i) {
|
||||
cmp = p+1;
|
||||
arch = _supported_archs[i];
|
||||
|
||||
/* whee, case insensitive compare */
|
||||
|
||||
while(*arch && *cmp && tolower(*arch++) == tolower(*cmp++)) ;
|
||||
if(*arch || *cmp) continue;
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
@ -72,7 +72,6 @@ int _alpm_check_freespace(pmtrans_t *trans, pmlist_t **data);
|
||||
#endif
|
||||
int _alpm_reg_match(char *string, char *pattern);
|
||||
void _alpm_time2string(time_t t, char *buffer);
|
||||
char *_alpm_pkgname_has_arch(char *pkgname);
|
||||
#ifdef __sun__
|
||||
char* strsep(char** str, const char* delims);
|
||||
char* mkdtemp(char *template);
|
||||
|
@ -23,8 +23,8 @@
|
||||
myver='2.9.8'
|
||||
|
||||
usage() {
|
||||
echo "gensync $myver"
|
||||
echo "usage: $0 <root> <destfile> [package_directory]"
|
||||
echo "gensync $myver"
|
||||
echo "usage: $0 <root> <destfile> [package_directory]"
|
||||
echo
|
||||
echo "gensync will generate a sync database by reading all PKGBUILD files"
|
||||
echo "from <root>. gensync builds the database in a temporary directory"
|
||||
@ -41,10 +41,12 @@ usage() {
|
||||
echo
|
||||
echo "example: gensync /var/abs/local /home/mypkgs/custom.db.tar.gz"
|
||||
echo
|
||||
echo
|
||||
exit 0
|
||||
echo
|
||||
exit 0
|
||||
}
|
||||
|
||||
source /etc/makepkg.conf
|
||||
|
||||
die() {
|
||||
echo "gensync: $*" >&2
|
||||
rm -rf $gstmpdir
|
||||
@ -65,11 +67,6 @@ check_option() {
|
||||
|
||||
get_md5checksum()
|
||||
{
|
||||
if [ "$pkgdir" != "" ]; then
|
||||
pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel.pkg.tar.gz"
|
||||
else
|
||||
pkgfile="$destdir/$pkgname-$pkgver-$pkgrel.pkg.tar.gz"
|
||||
fi
|
||||
if [ -f $pkgfile ]; then
|
||||
md5line=`md5sum $pkgfile`
|
||||
[ ! -z "$md5line" ] && pkgmd5sum=${md5line% *}
|
||||
@ -78,8 +75,33 @@ get_md5checksum()
|
||||
return 0
|
||||
}
|
||||
|
||||
get_sha1checksum()
|
||||
{
|
||||
if [ -f $pkgfile ]; then
|
||||
sha1line=`sha1sum $pkgfile`
|
||||
[ ! -z "$sha1line" ] && pkgsha1sum=${sha1line% *}
|
||||
echo $pkgsha1sum
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
db_write_entry()
|
||||
{
|
||||
if [ "$pkgdir" != "" ]; then
|
||||
pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT"
|
||||
else
|
||||
pkgfile="$destdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT"
|
||||
fi
|
||||
if [ ! -f $pkgfile ]; then
|
||||
die "Package '$pkgfile' not found"
|
||||
fi
|
||||
|
||||
csize=$(du -b $pkgfile | cut -f1)
|
||||
usize=$(LANG= LC_ALL= pacman -Qi -p $pkgfile 2>/dev/null|grep ^Size|sed 's/.*: \(.*\)/\1/')
|
||||
|
||||
pkgmd5sum=`get_md5checksum $pkgfile`
|
||||
[ -z $pkgmd5sum ] && die "error generating checksum for $pkgfile"
|
||||
|
||||
unset pkgname pkgver pkgrel pkgdesc force
|
||||
unset groups replaces provides depends conflicts options
|
||||
source $1 || return 1
|
||||
@ -106,11 +128,19 @@ db_write_entry()
|
||||
done
|
||||
echo "" >>desc
|
||||
fi
|
||||
echo "%ARCH%" >>desc
|
||||
echo "$arch" >>desc
|
||||
echo "" >>desc
|
||||
if [ -n $csize ]; then
|
||||
echo "%CSIZE%" >>desc
|
||||
echo "$csize" >>desc
|
||||
echo "" >>desc
|
||||
fi
|
||||
if [ -n $usize ]; then
|
||||
echo "%USIZE%" >>desc
|
||||
echo "$usize" >>desc
|
||||
echo "" >>desc
|
||||
fi
|
||||
if [ ! -z $pkgmd5sum ]; then
|
||||
echo "%MD5SUM%" >>desc
|
||||
echo "$pkgmd5sum" >>desc
|
||||
@ -132,21 +162,21 @@ db_write_entry()
|
||||
if [ ${#depends[*]} -gt 0 ]; then
|
||||
echo "%DEPENDS%" >>depends
|
||||
for it in "${depends[@]}"; do
|
||||
echo "$it" >>depends
|
||||
echo "$it" >>depends
|
||||
done
|
||||
echo "" >>depends
|
||||
fi
|
||||
if [ ${#conflicts[*]} -gt 0 ]; then
|
||||
echo "%CONFLICTS%" >>depends
|
||||
for it in "${conflicts[@]}"; do
|
||||
echo "$it" >>depends
|
||||
echo "$it" >>depends
|
||||
done
|
||||
echo "" >>depends
|
||||
fi
|
||||
if [ ${#provides[*]} -gt 0 ]; then
|
||||
echo "%PROVIDES%" >>depends
|
||||
for it in "${provides[@]}"; do
|
||||
echo "$it" >>depends
|
||||
echo "$it" >>depends
|
||||
done
|
||||
echo "" >>depends
|
||||
fi
|
||||
@ -180,15 +210,6 @@ echo "gensync: building database entries, generating md5sums..." >&2
|
||||
cd `dirname $2`
|
||||
for file in `find $rootdir/* -name PKGBUILD`; do
|
||||
source $file || die "errors parsing $file"
|
||||
if [ "$pkgdir" != "" ]; then
|
||||
pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel.pkg.tar.gz"
|
||||
else
|
||||
pkgfile="$destdir/$pkgname-$pkgver-$pkgrel.pkg.tar.gz"
|
||||
fi
|
||||
if [ -f $pkgfile ]; then
|
||||
csize=`du -b $pkgfile | cut -f1`
|
||||
pkgmd5sum=`get_md5checksum $pkgfile`
|
||||
[ -z $pkgmd5sum ] && die "error generating checksum for $pkgfile"
|
||||
db_write_entry $file || die "error writing entry for $file"
|
||||
else
|
||||
echo "gensync: missing package: $pkgfile" >&2
|
||||
@ -202,3 +223,4 @@ tar c * | gzip -9 >$destfile
|
||||
|
||||
rm -rf $gstmpdir
|
||||
exit 0
|
||||
# vim: set ts=2 sw=2 noet:
|
||||
|
@ -225,7 +225,7 @@ int split_pkgname(char *target, char *name, char *version)
|
||||
*p = '\0';
|
||||
}
|
||||
/* trim architecture */
|
||||
if((p = _alpm_pkgname_has_arch(tmp))) {
|
||||
if((p = alpm_pkg_name_hasarch(tmp))) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user