Sisyphus repositório
Última atualização: 1 outubro 2023 | SRPMs: 18631 | Visitas: 37726600
en ru br
ALT Linux repositórios
S:0.8.1-alt1

Group :: Desenvolvimento/Outros
RPM: apt-repo-tools

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs e FR  Repocop 

pax_global_header00006660000000000000000000000064123074312620014512gustar00rootroot0000000000000052 comment=faca09927be1d6bafde7372440dd5f735c06ea8f
apt-repo-tools-0.6.0.17/000075500000000000000000000000001230743126200146265ustar00rootroot00000000000000apt-repo-tools-0.6.0.17/.gear/000075500000000000000000000000001230743126200156225ustar00rootroot00000000000000apt-repo-tools-0.6.0.17/.gear/rules000064400000000000000000000000071230743126200166740ustar00rootroot00000000000000tar: .
apt-repo-tools-0.6.0.17/Makefile.am000064400000000000000000000004401230743126200166600ustar00rootroot00000000000000
bin_PROGRAMS = genpkglist gensrclist pkglist-query
bin_SCRIPTS = genbasedir

EXTRA_DIST = genbasedir

genpkglist_SOURCES = genpkglist.cc cached_md5.cc cached_md5.h genutil.h
gensrclist_SOURCES = gensrclist.cc cached_md5.cc cached_md5.h genutil.h
pkglist_query_SOURCES = pkglist-query.cc
apt-repo-tools-0.6.0.17/apt-repo-tools.spec000064400000000000000000000075141230743126200203760ustar00rootroot00000000000000Name: apt-repo-tools
Version: 0.6.0.17
Release: alt2

Summary: Utilities to create APT repositories
License: GPLv2+
Group: Development/Other

Source: %name-%version.tar

Provides: apt-utils = 0.5.15lorg4
Obsoletes: apt-utils <= 0.5.15lorg4

BuildRequires: gcc-c++ libapt-devel librpm-devel

%description
This package contains the utility programs that can prepare a repository
of RPMS binary and source packages for future access by APT (by
generating the indices): genbasedir, genpkglist, gensrclist.

%prep
%setup

%build
%autoreconf
%configure
%make_build

%install
%makeinstall_std
mkdir -p %buildroot/var/cache/apt/gen{pkg,src}list

%files
/usr/bin/genpkglist
/usr/bin/gensrclist
/usr/bin/genbasedir
/usr/bin/pkglist-query
%defattr(2770,root,rpm,2770)
%dir /var/cache/apt/genpkglist
%dir /var/cache/apt/gensrclist

%changelog
* Tue Mar 11 2014 Dmitry V. Levin <ldv@altlinux.org> 0.6.0.17-alt2
- Rebuilt.

* Fri Jan 11 2013 Dmitry V. Levin <ldv@altlinux.org> 0.6.0.17-alt1
- Enabled LFS support.

* Tue Apr 03 2012 Dmitry V. Levin <ldv@altlinux.org> 0.6.0.16-alt1
- gen{pkg,src}list: redirected all error messages to cerr,
made package read errors fatal.

* Fri Mar 30 2012 Dmitry V. Levin <ldv@altlinux.org> 0.6.0.15-alt1
- genbasedir: update release files properly (closes: #26260).

* Tue Nov 01 2011 Dmitry V. Levin <ldv@altlinux.org> 0.6.0.14-alt1
- genpkglist: add ttf and otf fonts to useful files
(by Igor Vlasenko; closes: #26520).

* Tue Aug 30 2011 Dmitry V. Levin <ldv@altlinux.org> 0.6.0.13-alt1
- genbasedir: synced with the version used by girar-builder.

* Thu Dec 23 2010 Alexey Tourbin <at@altlinux.ru> 0.6.0.12-alt1
- genbasedir: enabled --maybe-unchanged logic for srclists as well
- genbasedir: fixed --maybe-unchanged for multi-component repo (#24433)

* Sat Dec 18 2010 Alexey Tourbin <at@altlinux.ru> 0.6.0.11-alt1
- genbasedir: minor compression tweak

* Fri Dec 17 2010 Alexey Tourbin <at@altlinux.ru> 0.6.0.10-alt1
- genbasedir: renice bzip2 when running along with non-parallel xz

* Fri Dec 17 2010 Alexey Tourbin <at@altlinux.ru> 0.6.0.9-alt1
- genbasedir: implemented 2-way xz parallel compression

* Sun Nov 28 2010 Dmitry V. Levin <ldv@altlinux.org> 0.6.0.8-alt1
- genpkglist: add java jars to useful files (viy@; closes: #24649).

* Tue Aug 17 2010 Alexey Tourbin <at@altlinux.ru> 0.6.0.7-alt1
- genbasedir: implemented --maybe-unchanged option, for use in girar-builder

* Thu Jun 10 2010 Alexey Tourbin <at@altlinux.ru> 0.6.0.6-alt1
- genbasedir: added support for xz-compressed pkglists
- genbasedir: run bzip2 and xz in background

* Mon Dec 21 2009 Alexey I. Froloff <raorn@altlinux.org> 0.6.0.5-alt1.1
- NMU:
+ rebuilt with apt 0.5.15lorg2-alt31.1

* Sun Oct 25 2009 Alexey Tourbin <at@altlinux.ru> 0.6.0.5-alt1
- genpkglist.cc: implemented "--changelog-since seconds" option
- genbasedir: implemented --changelog-since=DATE option

* Sun Oct 25 2009 Alexey Tourbin <at@altlinux.ru> 0.6.0.4-alt1
- genpkglist.cc: group binary packages by src.rpm

* Sun Sep 27 2009 Alexey Tourbin <at@altlinux.ru> 0.6.0.3-alt1
- genpkglist.cc: fixed first-pass memory leak

* Tue Jul 14 2009 Alexey Tourbin <at@altlinux.ru> 0.6.0.2-alt1
- genbasedir: replaced 'bzip2 -9' with 'bzip2', to make BZIP2=--fast work

* Thu Jul 09 2009 Alexey Tourbin <at@altlinux.ru> 0.6.0.1-alt1
- genpkglist: added /usr/games and /usr/lib/kde4bin directories

* Wed Apr 22 2009 Alexey Tourbin <at@altlinux.ru> 0.6.0-alt1
- this package provides and obsoletes apt-utils
- genpkglist: reimplemented support for file-level dependencies
- genpkglist: removed /etc/ from usefulFile patterns
- genpkglist: file dups are now stripped as well
- genpkglist: added --useful-files=FILE option
- genpkglist: added --no-scan option
- genbasedir: pass --no-scan and --useful-files=FILE to genpkglist
- genbasedir: pass --cache-dir=DIR to genpkglist and gensrclist
- pkglist-query: new program, obsoletes countpkglist
apt-repo-tools-0.6.0.17/cached_md5.cc000064400000000000000000000043031230743126200171110ustar00rootroot00000000000000/*
* $Id: cached_md5.cc,v 1.4 2003/01/29 13:47:31 niemeyer Exp $
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <alloca.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <rpm/rpmlib.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>

#include "cached_md5.h"

#include <apt-pkg/error.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/md5.h>

CachedMD5::CachedMD5(string DirName, string Domain)
{
string fname = DirName;
for (string::iterator i = fname.begin(); i != fname.end(); ++i)
if ('/' == *i)
*i = '_';
CacheFileName = _config->FindDir("Dir::Cache", "/var/cache/apt") + '/' +
Domain + '/' + fname + ".md5cache";

FILE *f = fopen(CacheFileName.c_str(), "r");
if (!f)
return;

while (1)
{
char buf[BUFSIZ];
if (!fgets(buf, sizeof(buf), f))
break;
char *p1 = strchr(buf, ' ');
assert(p1);

string File;
File = string(buf, p1++);
char *p2 = strchr(p1, ' ');
assert(p2);

FileData Data;
Data.MD5 = string(p1, p2++);
Data.TimeStamp = atol(p2);
MD5Table[File] = Data;
}

fclose(f);
}


CachedMD5::~CachedMD5()
{
FILE *f = fopen(CacheFileName.c_str(), "w+");
if (f)
{
for (map<string,FileData>::const_iterator I = MD5Table.begin();
I != MD5Table.end(); I++ )
{
const string &File = (*I).first;
const FileData &Data = (*I).second;
fprintf(f, "%s %s %lu\n",
File.c_str(), Data.MD5.c_str(), Data.TimeStamp );
}
fclose(f);
}
}

void CachedMD5::MD5ForFile(string FileName, time_t TimeStamp, char *buf)
{
if (MD5Table.find(FileName) != MD5Table.end()
&& TimeStamp == MD5Table[FileName].TimeStamp )
{
strcpy(buf, MD5Table[FileName].MD5.c_str());
}
else
{
MD5Summation MD5;
FileFd File(FileName, FileFd::ReadOnly);
MD5.AddFD(File.Fd(), File.Size());
File.Close();
FileData Data;
Data.MD5 = MD5.Result().Value();
Data.TimeStamp = TimeStamp;
MD5Table[FileName] = Data;
strcpy(buf, Data.MD5.c_str());
}
}

// vim:sts=3:sw=3
apt-repo-tools-0.6.0.17/cached_md5.h000064400000000000000000000031451230743126200167560ustar00rootroot00000000000000/*
* $Id: cached_md5.h,v 1.4 2003/01/29 13:47:31 niemeyer Exp $
*
* $Log: cached_md5.h,v $
* Revision 1.4 2003/01/29 13:47:31 niemeyer
* Patch by Dmitry V. Levin <ldv@altlinux.org>
*
* * tools/cached_md5.h(CachedMD5::CachedMD5):
* Add additional argument (Domain).
* * tools/cached_md5.cc(CachedMD5::CachedMD5):
* Use passed argument (Domain) instead of __progname.
* * tools/genpkglist.cc(main): Pass additional argument to CachedMD5.
* * tools/gensrclist.cc(main): Likewise.
*
* CachedMD5 constructor uses __progname which is wrong in some cases (e.g.
* genbasedir renamed to smth else). I'm guilty of introducing this code in
* apt-rpm, so I suggest to fix it.
*
* Revision 1.3 2002/07/26 23:22:27 niemeyer
* Use APT's MD5 implementation.
*
* Revision 1.2 2002/07/26 17:39:28 niemeyer
* Changes for GCC 3.1 and RPM 4.1 support (merged patch from Enrico Scholz).
*
* Revision 1.1 2002/07/23 17:54:53 niemeyer
* Added to CVS.
*
* Revision 1.1 2001/08/07 20:46:03 kojima
* Alexander Bokovoy <a.bokovoy@sam-solutions.net>'s patch for cleaning
* up genpkglist
*
*
*/

#ifndef __CACHED_MD5_H__
#define __CACHED_MD5_H__

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <sys/types.h>
#include <string>
#include <map>

using namespace std;

class CachedMD5
{
string CacheFileName;
struct FileData
{
string MD5;
time_t TimeStamp;
};
map<string, FileData> MD5Table;

public:

void MD5ForFile(string FileName, time_t TimeStamp, char *buf);

CachedMD5(string DirName, string Domain);
~CachedMD5();
};

#endif /* __CACHED_MD5_H__ */

// vim:sts=3:sw=3
apt-repo-tools-0.6.0.17/configure.ac000064400000000000000000000031531230743126200171160ustar00rootroot00000000000000AC_INIT([apt-repo-tools],[0.6.0],[at@altlinux.org])
AC_CONFIG_SRCDIR([genpkglist.cc])
AM_INIT_AUTOMAKE([foreign])

AC_PROG_CXX
AC_SYS_LARGEFILE
AC_PROG_LIBTOOL

AC_MSG_CHECKING(for RPM version)
RPM_VERSION_RAW=`LANG=C LC_ALL=C rpm --version | sed 's/^RPM version //'`
RPM_VERSION_MAJOR=`echo $RPM_VERSION_RAW | cut -d. -f1`
RPM_VERSION_MINOR=`echo $RPM_VERSION_RAW | cut -d. -f2`
RPM_VERSION_MICRO=`echo $RPM_VERSION_RAW | cut -d. -f3`
if test -z "$RPM_VERSION_MAJOR" -o -z "$RPM_VERSION_MINOR"; then
AC_MSG_ERROR([can't parse RPM version])
fi
if test -z "$RPM_VERSION_MICRO"; then
RPM_VERSION_MICRO=0
fi
AC_DEFINE_UNQUOTED([RPM_VERSION_MAJOR],$RPM_VERSION_MAJOR,[RPM major version])
AC_DEFINE_UNQUOTED([RPM_VERSION_MINOR],$RPM_VERSION_MINOR,[RPM minor version])
AC_DEFINE_UNQUOTED([RPM_VERSION_MICRO],$RPM_VERSION_MICRO,[RPM micro version])
AC_DEFINE_UNQUOTED([RPM_VERSION],
[((RPM_VERSION_MAJOR<<16)|(RPM_VERSION_MINOR<<8)|RPM_VERSION_MICRO)],
[Define to the RPM version])
AC_DEFINE_UNQUOTED([RPM_VERSION_RAW],"$RPM_VERSION_RAW",[RPM raw version])
AC_MSG_RESULT($RPM_VERSION_RAW)

AC_CHECK_HEADER([rpm/rpmlib.h],,
[AC_MSG_ERROR([rpm headers not found])] )
AC_CHECK_LIB([rpm],[main],,
[AC_MSG_ERROR([rpm library not found])] )
AC_CHECK_LIB([rpmdb],[main],,
[AC_MSG_ERROR([rpmdb library not found])] )
AC_CHECK_LIB([rpmio],[main],,
[AC_MSG_ERROR([rpmio library not found])] )

AC_LANG_CPLUSPLUS
AC_CHECK_HEADER([apt-pkg/configuration.h],,
[AC_MSG_ERROR([apt-pkg headers not found])] )
AC_CHECK_LIB([apt-pkg], [main],,
[AC_MSG_ERROR([apt-pkg library not found])] )

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
apt-repo-tools-0.6.0.17/crpmtag.h000064400000000000000000000007701230743126200164400ustar00rootroot00000000000000
#define CRPMTAG_FILENAME (rpmTag)1000000
#define CRPMTAG_FILESIZE (rpmTag)1000001
#define CRPMTAG_MD5 (rpmTag)1000005
#define CRPMTAG_SHA1 (rpmTag)1000006

#define CRPMTAG_DIRECTORY (rpmTag)1000010
#define CRPMTAG_BINARY (rpmTag)1000011

#define CRPMTAG_UPDATE_SUMMARY (rpmTag)1000020
#define CRPMTAG_UPDATE_IMPORTANCE (rpmTag)1000021
#define CRPMTAG_UPDATE_DATE (rpmTag)1000022
#define CRPMTAG_UPDATE_URL (rpmTag)1000023

apt-repo-tools-0.6.0.17/genbasedir000075500000000000000000000366741230743126200166770ustar00rootroot00000000000000#! /bin/sh
#
# Modified by ALT Linux Team <apt@packages.altlinux.org>.
# Last change by Sviatoslav Sviridov <svd@altlinux.ru>.
# genbasedir was rewritten as mix of genbasedir scripts
# from Connectiva's apt-0.5.4cnc9 and ALT Linux Team's
# apt-0.3.19cnc55-alt9.
#
# The previous version from apt-0.5.4cnc9 was:
# $Id: genbasedir,v 1.6 2002/09/04 22:48:37 niemeyer Exp $
#
# This script generates the contents of the base/ directory, by creating
# the pkglists and the hash file. Update the components directory to contain
# the components of your repository.
#

PROG="${0##*/}"

topdir=

basedir=.
signature=
listonly=
hashonly=
partial=
newhashfile=1
oldhashfile=1
mapi=
bz2only=
updateinfo=
progress=
flat=
defaultkey=
topdir=
create=
verbose=
cachedir=
useful_files=

maybe_unchanged=
unchanged=1

# bloat is necessary for non-Conectiva distros, at least RH,
# because they use file dependencies with a non-predictable
# heuristic. So we can't strip-off paths that will probably
# never appear in dependencies.
bloat=
noscan=

# Global release file sections
origin="Unknown"
label="Unknown"
suite="Unknown"
codename="Unknown"
date="`date -R`"
architectures="Unknown"
description="Not Available"

# Component release file sections
archive="Unknown"
version="Unknown"
architecture="Unknown"
notautomatic="false"

changelog_since=

make_bz2=1
make_xz=1

Fatal()
{
echo "${0##*/}: $*" >&2
exit 1
}

Verbose()
{
if [ -n "$verbose" ]; then
echo "$@"
fi
}

USAGE()
{
cat >&2 <<EOF
Usage: ${0##*/} [<options>] <distribution> [<comp1> [<comp2> ...]]

Options:
-s, --sign Generate and sign hashfile
--default-key=ID Use ID as gnupg secret key
--hashonly Do hash stuff only
--listonly Generate pkglists/srclists and quit
--partial Update just some of the already existent components
--newhashfile Enable generation of new style hashfile
--no-newhashfile Disable generation of new style hashfile
--oldhashfile Enable generation of old style hashfile
--no-oldhashfile Disable generation of old style hashfile
--bz2only Generate only compressed lists
--progress Show progress bars for genpkglist/gensrclist;
implies --verbose
-v, --verbose Be more talkative
--silent Be less talkative (default)
--topdir=dir Top directory of repository
--updateinfo=FILE Update information file
--mapi List only those pkgs in srclist which generate
some binaries
--flat Use flat repository, where SRPMS and RPMS are in
the topdir (SRPMS are usually in 'topdir/..')
--no-scan Do not scan for useful files.
--bloat Do not strip the package file list. Needed for some
distributions that use non-automatically generated
file dependencies
--useful-files=FILE
Read the list of useful files from FILE.
Do not strip these files from the package file list.
--create Create base directory if needed

--origin=ORIGIN Set "Origin" field in global release file
--label=LABEL Set "Label" field in global release file
--suite=SUITE Set "Suite" field in global release file
--codename=CODENAME
Set "Codename" field in global release file
--architectures=ARCHITECTURES
Set "Architectures" field in global release file
--description=DESCRIPTION
Set "Description" field in global release file

--archive=ARCHIVE Set "Archive" field in component release file
--version=VERSION Set "Version" field in component release file
--architecture=ARCHITECTURE
Set "Architecture" field in component release file
--notautomatic=true|false Set "NotAutomatic" field in component release file
--cachedir=DIR Use a custom md5sum cache directory for package list
--changelog-since=DATE Save package changelogs; copy changelog entries
newer than DATE, and also one preceding entry
--maybe-unchanged Skip the update if pkglist is unchanged.

-h,--help Show this help screen

Examples:

${0##*/} --topdir=/var/ftp/pub/distributions/ALTLinux/Sisyphus i586
${0##*/} --topdir=/var/ftp/pub/distributions/ALTLinux/Sisyphus i586 base kernel castle junior master contrib classic non-free
EOF
[ -n "$1" ] && exit "$1" || exit
}

phashstuff()
{
size=`wc -c <"$1"`
md5=`md5sum "$1"|cut -f1 -d\ `
echo " $md5 $size $2"
}

TEMP=`getopt -n $PROG -o vhs -l help,mapi,listonly,bz2only,hashonly,updateinfo:,bloat,no-scan,topdir:,sign,default-key:,progress,verbose,silent,oldhashfile,newhashfile,no-oldhashfile,no-newhashfile,partial,flat,create,origin:,label:,suite:,codename:,architectures:,description:,archive:,version:,architecture:,notautomatic:,cachedir:,useful-files:,changelog-since: \
-l bz2,no-bz2,xz,no-xz,maybe-unchanged -- "$@"` || USAGE
eval set -- "$TEMP"

while :; do
case "$1" in
--listonly) shift; listonly=1
;;
--bz2only) shift; bz2only=1
;;
--hashonly) shift; hashonly=1
;;
-s|--sign) shift; signature=1
;;
--bloat) shift; bloat="--bloat"
;;
--no-scan) shift; noscan="--no-scan"
;;
--mapi) shift; mapi="--mapi"
;;
--updateinfo) shift; updateinfo="$1"; shift
;;
--default-key) shift; defaultkey="$1"; shift
;;
--topdir) shift; topdir="$1"; shift
;;
--flat) shift; flat="--flat"
;;
--progress) shift; progress="--progress"; verbose=1
;;
-v|--verbose) shift; verbose=1
;;
--silent) shift; verbose=
;;
--partial) shift; partial=1
;;
--oldhashfile) shift; oldhashfile=1
;;
--no-oldhashfile) shift; oldhashfile=
;;
--newhashfile) shift; newhashfile=1
;;
--no-newhashfile) shift; newhashfile=
;;
-h|--help) USAGE 0
;;
--create) shift; create=1
;;
--origin) shift; origin="$1"; shift
;;
--label) shift; label="$1"; shift
;;
--suite) shift; suite="$1"; shift
;;
--codename) shift; codename="$1"; shift
;;
--architectures) shift; architectures="$1"; shift;
;;
--description) shift; description="$1"; shift;
;;
--archive) shift; archive="$1"; shift;
;;
--version) shift; version="$1"; shift;
;;
--architecture) shift; architecture="$1"; shift;
;;
--notautomatic) shift; notautomatic="$1"; shift;
;;
--changelog-since) shift
changelog_since=$(date -d "$1" +%s) &&
[ "$changelog_since" -gt 0 ] ||
Fatal "invalid --changelog-since date: $1"
shift ;;
--cachedir) shift; cachedir="$1"; shift;
;;
--useful-files) shift; useful_files="$1"; shift;
;;
--bz2) shift; make_bz2=1 ;;
--no-bz2) shift; make_bz2= ;;
--xz) shift; make_xz=1 ;;
--no-xz) shift; make_xz= ;;
--maybe-unchanged) shift; maybe_unchanged=1 ;;
--) shift; break
;;
*) echo "$PROG: unrecognized option: $1" >&2; exit 1
;;
esac
done

topdir="`echo -n "$topdir" |tr -s /`"

[ -n "$topdir" ] || Fatal 'TOPDIR not specified.'

cd "$topdir" || Fatal "Invalid TOPDIR specified: $topdir"

# this will fix the path if it was relative
topdir=`pwd`

distro="$1"
shift

components="$*"

basedir_=base
oldbasedir_="`echo "$distro/$basedir_"|tr -s /`"
basedir="`echo "$topdir/$oldbasedir_"|tr -s /`"

pkglist_=$basedir_/pkglist
srclist_=$basedir_/srclist
release_=$basedir_/release
oldpkglist_=$oldbasedir_/pkglist
oldsrclist_=$oldbasedir_/srclist
oldrelease_=$oldbasedir_/release
pkglist=$basedir/pkglist
srclist=$basedir/srclist
release=$basedir/release

if [ -z "$flat" ]; then
srctopdir=`cd $topdir/$distro/..; pwd`
else
srctopdir=`cd $topdir/$distro; pwd`
fi

WORKDIR=
exit_handler()
{
[ -z "$WORKDIR" ] || rm -rf -- "$WORKDIR"
exit $1
}
trap 'exit_handler $?' EXIT
trap 'exit 143' HUP PIPE INT QUIT TERM
WORKDIR="$(mktemp -dt "$PROG.XXXXXXXXXX")" || exit

if [ ! -d "$basedir" ]; then
if [ -n "$create" ]; then
Verbose -n 'Creating base directory... '
if ! mkdir -p "$basedir" >/dev/null 2>&1; then
Fatal 'Unable to create base directory'
fi
Verbose 'done'
else
Fatal 'Base directory does not exist!'
fi
fi

if [ -z "$components" ]; then
# Try to guess components
comps=$WORKDIR/components
: >$comps
for dir in $topdir/$distro/RPMS.* $srctopdir/SRPMS.*; do
if [ -d $dir ]; then
echo $dir | sed 's/.*\.//' >> $comps
fi
done
components=`cat $comps|sort|uniq`
components=`echo $components` # eat newlines
rm -f $comps
fi

if [ -z "$components" ]; then
Fatal 'No components found'
else
Verbose "Components: $components"
fi

saved_list=

save_file()
{
saved_list="$1"

if [ -f "$saved_list" ]; then
mv -f "$saved_list" "$saved_list.old"
else
saved_list=
fi
}

compare_file()
{
if [ -n "$saved_list" -a -f "$saved_list.old" ]; then
if cmp -s "$saved_list.old" "$saved_list"; then
mv -f "$saved_list.old" "$saved_list"
else
rm -f "$saved_list.old"
fi
fi
}

compress_file()
{
local filesize halfsize pid pxz=

rm -f "$1.xz" "$1.yz"
if [ -n "$make_xz" ]; then
filesize=$(stat -c '%s' "$1")
if [ "$filesize" -ge $((4*8*1024*1024)) ]; then
# The file is large enough (as compared to typical dictionary size).
# Note that .xz files can be concatenated, so it's nice to have
# 2-way parallel compression here.
pxz=1
fi
if [ -n "$pxz" ]; then
halfsize=$(($filesize/2))
dd if="$1" bs="$halfsize" count=1 2>/dev/null |xz >"$1.xz" & pid=$!
dd if="$1" bs="$halfsize" skip=1 2>/dev/null |xz >"$1.yz"
wait "$pid"
cat "$1.yz" >>"$1.xz"
rm -f "$1.yz"
else
xz -k "$1"
fi &
fi

rm -f "$1.bz2"
if [ -n "$make_bz2" ]; then
if [ -n "$pxz" ]; then
bzip2 -k "$1"
else
# Assuming non-parallel xz is expensive...
nice bzip2 -k "$1"
fi &
fi
}

if [ -n "$cachedir" ]; then
mkdir -p "$cachedir/genpkglist" "$cachedir/gensrclist"
fi

if [ -z "$hashonly" ]; then
Verbose -n 'Processing packages...'

for comp in $components; do

SRCIDX_COMP="$WORKDIR/$comp"

# pkglist
if [ ! -d $topdir/$distro/RPMS.$comp ]; then
# remove stale lists
rm -f "$pkglist.$comp" "$pkglist.$comp".{bz2,xz}
rm -f "$srclist.$comp" "$srclist.$comp".{bz2,xz}
continue
fi
Verbose -n " RPMS.$comp"
save_file "$pkglist.$comp"
(cd "$basedir" &&
genpkglist $progress $bloat $noscan --index "$SRCIDX_COMP" \
${updateinfo:+--info "$updateinfo"} \
${cachedir:+--cachedir "$cachedir"} \
${useful_files:+--useful-files "$useful_files"} \
${changelog_since:+--changelog-since "$changelog_since"} \
"$topdir/$distro" "$comp")
if [ $? -ne 0 ]; then
Verbose
Fatal 'Error executing genpkglist.'
fi
compare_file
if [ -n "$maybe_unchanged" ]; then
hash=$(phashstuff "$pkglist.$comp" "$pkglist_.$comp")
if LC_ALL=C fgrep -qs -x "$hash" "$release"; then
Verbose "$pkglist.$comp is unchanged"
continue
else
Verbose "$pkglist.$comp is going to be changed despite --maybe-unchanged"
fi
unchanged=
fi
compress_file "$pkglist.$comp"

# srclist
if [ ! -d $srctopdir/SRPMS.$comp ]; then
# remove stale lists
rm -f "$srclist.$comp" "$srclist.$comp".{bz2,xz}
continue
fi
save_file "$srclist.$comp"
(cd "$basedir" &&
gensrclist $progress $flat $mapi \
${cachedir:+--cachedir "$cachedir"} \
"$srctopdir" "$comp" "$SRCIDX_COMP")
if [ $? -ne 0 ]; then
Verbose
Fatal 'Error executing gensrclist.'
fi
compare_file
if [ -n "$maybe_unchanged" ]; then
hash=$(phashstuff "$srclist.$comp" "$srclist_.$comp")
if LC_ALL=C fgrep -qs -x "$hash" "$release"; then
Verbose "$srclist.$comp is unchanged"
continue
else
Verbose "$srclist.$comp is going to be changed despite --maybe-unchanged"
fi
unchanged=
fi
compress_file "$srclist.$comp"

done
Verbose ' done'

Verbose -n 'Waiting for bzip2 and xz to finish...'
wait
Verbose ' done'
fi

remove_uncompressed()
{
if [ -n "$bz2only" ]; then
for comp in $components; do
rm -f "$pkglist.$comp" "$srclist.$comp"
done
fi
}

if [ -n "$maybe_unchanged" ] && [ -n "$unchanged" ]; then
remove_uncompressed
Verbose "$release is unchanged"
exit 0
fi

phash()
{
if [ -f "$1" ]; then
phashstuff "$1" "$2" >> "$3"
fi
}

# Creating new style hashfile
if [ -n "$newhashfile" -a -z "$listonly" ]; then
Verbose -n 'Creating component releases...'
for comp in $components; do
Verbose -n " $comp"
save_file "$release.$comp"
cat > "$release.$comp" <<- __EOF__
Archive: $archive
Component: $comp
Version: $version
Origin: $origin
Label: $label
Architecture: $architecture
NotAutomatic: $notautomatic
__EOF__
compare_file
done
Verbose ' done'

Verbose -n 'Updating global release file... '
save_file "$release"
if [ -f "$release" -a -n "$partial" ]; then
sed -n -e "/^\$/q" \
-e "s/^Date:.*\$/Date: $date/" \
-e "p" "$release.old" > "$release.pre"
for comp in $components; do
sed -e "\#^ .* $pkglist_.$comp\(.bz2\)\?\$#d" \
-e "\#^ .* $srclist_.$comp\(.bz2\)\?\$#d" \
-e "\#^ .* $release_.$comp\(.bz2\)\?\$#d" \
-e "\#^ .* $pkglist_.$comp\(.xz\)\?\$#d" \
-e "\#^ .* $srclist_.$comp\(.xz\)\?\$#d" \
-e "\#^ .* $release_.$comp\(.xz\)\?\$#d" \
-e "s/^\(Components:.*\) $comp\(.*\)\$/\1\2/" \
"$release.pre" > "$release.tmp"
mv -f "$release.tmp" "$release.pre"
done
sed -e "s/^\(Components:.*\)\$/\1 $components/" \
"$release.pre" > "$release"
rm -f "$release.pre"
else
cat > "$release" <<- __EOF__
Origin: $origin
Label: $label
Suite: $suite
Codename: $codename
Date: `date -R`
Architectures: $architectures
Components: $components
Description: $description
MD5Sum:
__EOF__
fi
compare_file
Verbose 'done'

Verbose -n 'Appending MD5Sum...'
for comp in $components; do
Verbose -n " $comp"
phash "$pkglist.$comp" "$pkglist_.$comp" "$release"
phash "$srclist.$comp" "$srclist_.$comp" "$release"
phash "$pkglist.$comp.bz2" "$pkglist_.$comp.bz2" "$release"
phash "$srclist.$comp.bz2" "$srclist_.$comp.bz2" "$release"
phash "$pkglist.$comp.xz" "$pkglist_.$comp.xz" "$release"
phash "$srclist.$comp.xz" "$srclist_.$comp.xz" "$release"
phash "$release.$comp" "$release_.$comp" "$release"
done
Verbose ' done'

echo >> "$release"

if [ -n "$signature" ]; then
if [ -n "$defaultkey" ]; then
gpg -armour --quiet --detach-sign --yes --default-key "$defaultkey" "$release"
else
gpg -armour --quiet --detach-sign --yes "$release"
fi

cat "$release.asc" >>"$release"
rm -f "$release.asc"
fi

# Compare with older release
compare_file
fi

# Creating old style hashfile
if [ -n "$oldhashfile" -a -z "$listonly" ]; then
hf="$basedir/hashfile"
save_file "$hf"
: > "$hf"

# TODO: handle 'partial' option

Verbose -n 'Creating legacy hashfile...'
echo "MD5SUM:" >> $hf

for comp in $components; do
Verbose -n " $comp"

phash "$pkglist.$comp" "$oldpkglist_.$comp" "$hf"
phash "$srclist.$comp" "$oldsrclist_.$comp" "$hf"
phash "$pkglist.$comp.bz2" "$oldpkglist_.$comp.bz2" "$hf"
phash "$srclist.$comp.bz2" "$oldsrclist_.$comp.bz2" "$hf"
phash "$pkglist.$comp.xz" "$oldpkglist_.$comp.xz" "$hf"
phash "$srclist.$comp.xz" "$oldsrclist_.$comp.xz" "$hf"
phash "$release.$comp" "$oldrelease_.$comp" "$hf"
done
Verbose ' done'
echo >> $hf

compare_file

if [ -n "$signature" ]; then
# Save older hashfile.gpg
save_file "$basedir/hashfile.gpg"

if [ -n "$defaultkey" ]; then
gpg -armour --quiet --sign --yes -o "$basedir/hashfile.gpg" --default-key "$defaultkey" "$basedir/hashfile"
else
gpg -armour --quiet --sign --yes -o "$basedir/hashfile.gpg" "$basedir/hashfile"
fi

# Compare with older hashfile.gpg
compare_file
fi
fi

remove_uncompressed

Verbose 'All your base are belong to us!!!'

# vim:ts=4:sw=4
apt-repo-tools-0.6.0.17/genpkglist.cc000064400000000000000000000360771230743126200173210ustar00rootroot00000000000000/*
* $Id: genpkglist.cc,v 1.7 2003/01/30 17:18:21 niemeyer Exp $
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <alloca.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <rpm/rpmlib.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <assert.h>

#include <map>
#include <set>
#include <iostream>
#include <fstream>

#include <apt-pkg/error.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/configuration.h>

#include "rapt-compat.h"
#include "crpmtag.h"
#include "cached_md5.h"
#include "genutil.h"

raptTag tags[] = {
RPMTAG_NAME,
RPMTAG_EPOCH,
RPMTAG_VERSION,
RPMTAG_RELEASE,
RPMTAG_GROUP,
RPMTAG_ARCH,
RPMTAG_PACKAGER,
RPMTAG_SOURCERPM,
RPMTAG_SIZE,
RPMTAG_VENDOR,
RPMTAG_OS,

RPMTAG_DESCRIPTION,
RPMTAG_SUMMARY,
/*RPMTAG_HEADERI18NTABLE*/ HEADER_I18NTABLE,

RPMTAG_REQUIREFLAGS,
RPMTAG_REQUIRENAME,
RPMTAG_REQUIREVERSION,

RPMTAG_CONFLICTFLAGS,
RPMTAG_CONFLICTNAME,
RPMTAG_CONFLICTVERSION,

RPMTAG_PROVIDENAME,
RPMTAG_PROVIDEFLAGS,
RPMTAG_PROVIDEVERSION,

RPMTAG_OBSOLETENAME,
RPMTAG_OBSOLETEFLAGS,
RPMTAG_OBSOLETEVERSION
};
int numTags = sizeof(tags) / sizeof(tags[0]);


static
void copyChangelog(Header h1, Header h2, long since)
{
int_32 timet, namet, textt;
int_32 *time = NULL;
const char **name = NULL, **text = NULL;
int_32 n = 0; // in
int_32 m = 0; // out
int i;
int rc = headerGetEntry(h1, RPMTAG_CHANGELOGTIME, &timet, (void**)&time, &n)
&& headerGetEntry(h1, RPMTAG_CHANGELOGNAME, &namet, (void**)&name, NULL)
&& headerGetEntry(h1, RPMTAG_CHANGELOGTEXT, &textt, (void**)&text, NULL);
if (!rc || n < 1)
goto exit;

for (i = 0; i < n; i++)
if (time[i] >= since)
m++;
else
break;
if (m < n)
m++;

headerAddEntry(h2, RPMTAG_CHANGELOGTIME, timet, time, m);
headerAddEntry(h2, RPMTAG_CHANGELOGNAME, namet, name, m);
headerAddEntry(h2, RPMTAG_CHANGELOGTEXT, textt, text, m);

exit:
headerFreeData(time, (rpmTagType)timet);
headerFreeData(name, (rpmTagType)namet);
headerFreeData(text, (rpmTagType)textt);
}


static
bool usefulFile(const char *d, const char *b,
const set<string> &depFiles)
{
// PATH-like directories
if (endswith(d, "/bin/") || endswith(d, "/sbin/"))
return true;
if (strcmp(d, "/usr/games/") == 0)
return true;
if (strcmp(d, "/usr/lib/kde4bin/") == 0)
return true;
// Java jars
if (strncmp(d, "/usr/share/java/", sizeof("/usr/share/java/") - 1) == 0
&& endswith(b, ".jar"))
return true;
// ttf and otf fonts
if (strncmp(d, "/usr/share/fonts/", sizeof("/usr/share/fonts/") - 1) == 0
&& (endswith(b, ".ttf") || endswith(b, ".otf")))
return true;

// shared libraries
if (strncmp(b, "lib", 3) == 0 && strstr(b + 3, ".so"))
return true;

// required by other packages
if (depFiles.find(string(d) + b) != depFiles.end()) {
// fprintf(stderr, "useful depfile: %s%s\n", d, b);
return true;
}

return false;
}


static
void copyStrippedFileList(Header h1, Header h2,
const set<string> &depFiles)
{
raptTagType bnt, dnt, dit;
struct {
raptTagCount bnc, dnc, dic;
const char **bn, **dn;
raptInt *di;
}
l1 = {0}, l2 = {0};

int rc;
rc = headerGetEntry(h1, RPMTAG_BASENAMES, &bnt, (void**)&l1.bn, &l1.bnc);
if (rc != 1)
return;
assert(bnt == RPM_STRING_ARRAY_TYPE);
assert(l1.bnc > 0);

rc = headerGetEntry(h1, RPMTAG_DIRNAMES, &dnt, (void**)&l1.dn, &l1.dnc);
assert(rc == 1);
assert(dnt == RPM_STRING_ARRAY_TYPE);

rc = headerGetEntry(h1, RPMTAG_DIRINDEXES, &dit, (void**)&l1.di, &l1.dic);
assert(rc == 1);
assert(dit == RPM_INT32_TYPE);
assert(l1.bnc == l1.dic);

for (int i = 0; i < l1.bnc; i++)
{
const char *d = l1.dn[l1.di[i]];
const char *b = l1.bn[i];

if (!usefulFile(d, b, depFiles))
continue;

if (l2.bnc == 0) {
l2.bn = new const char *[l1.bnc];
l2.dn = new const char *[l1.dnc];
l2.di = new raptInt[l1.dic];
}

l2.bn[l2.bnc++] = b;

bool has_dir = false;
for (int j = 0; j < l2.dnc; j++) {
if (l2.dn[j] == d) {
l2.di[l2.dic++] = j;
has_dir = true;
break;
}
}
if (!has_dir) {
l2.dn[l2.dnc] = d;
l2.di[l2.dic++] = l2.dnc++;
}
}

assert(l2.bnc == l2.dic);

if (l2.bnc > 0) {
headerAddEntry(h2, RPMTAG_BASENAMES, bnt, l2.bn, l2.bnc);
headerAddEntry(h2, RPMTAG_DIRNAMES, dnt, l2.dn, l2.dnc);
headerAddEntry(h2, RPMTAG_DIRINDEXES, dit, l2.di, l2.dic);
delete[] l2.bn;
delete[] l2.dn;
delete[] l2.di;
}

headerFreeData(l1.bn, (rpmTagType)bnt);
headerFreeData(l1.dn, (rpmTagType)dnt);
headerFreeData(l1.di, (rpmTagType)dit);
}


static
void findDepFiles(Header h, set<string> &depFiles, raptTag tag)
{
raptTagType type;
raptTagCount count;
raptTagData data;
int rc = headerGetEntry(h, tag, &type, &data, &count);
if (rc != 1)
return;
assert(type == RPM_STRING_ARRAY_TYPE);
const char **deps = (const char **) data;
for (int i = 0; i < count; i++) {
const char *dep = deps[i];
if (*dep == '/')
depFiles.insert(dep);
}
headerFreeData(data, (rpmTagType)type);
}


typedef struct {
string importance;
string date;
string summary;
string url;
} UpdateInfo;


static
bool loadUpdateInfo(char *path, map<string,UpdateInfo> &M)
{
FileFd F(path, FileFd::ReadOnly);
if (_error->PendingError())
{
return false;
}

pkgTagFile Tags(&F);
pkgTagSection Section;

while (Tags.Step(Section))
{
string file = Section.FindS("File");
UpdateInfo info;

info.importance = Section.FindS("Importance");
info.date = Section.FindS("Date");
info.summary = Section.FindS("Summary");
info.url = Section.FindS("URL");

M[file] = info;
}
return true;
}


static
void addInfoTags(Header h, const char *fname,
const map<string,UpdateInfo> &M)
{
map<string,UpdateInfo>::const_iterator I = M.find(fname);
if (I == M.end())
return;
const UpdateInfo &info = I->second;
addStringTag(h, CRPMTAG_UPDATE_SUMMARY, info.summary.c_str());
addStringTag(h, CRPMTAG_UPDATE_URL, info.url.c_str());
addStringTag(h, CRPMTAG_UPDATE_DATE, info.date.c_str());
addStringTag(h, CRPMTAG_UPDATE_IMPORTANCE, info.importance.c_str());
}


void usage()
{
cerr << "genpkglist " << VERSION << endl;
cerr << "usage: genpkglist [<options>] <dir> <suffix>" << endl;
cerr << "options:" << endl;
cerr << " --index <file> file to write srpm index data to" << endl;
cerr << " --info <file> file to read update info from" << endl;
cerr << " --useful-files <file> file to read the list of useful files from" << endl;
cerr << " --meta <suffix> create package file list with given suffix" << endl;
cerr << " --no-scan do not scan for useful files" << endl;
cerr << " --bloat do not strip the package file list. Needed for some" << endl;
cerr << " distributions that use non-automatically generated" << endl;
cerr << " file dependencies" << endl;
cerr << " --append append to the package file list, don't overwrite" << endl;
cerr << " --progress show a progress bar" << endl;
cerr << " --cachedir=DIR use a custom directory for package md5sum cache"<<endl;
cerr << " --changelog-since <seconds>" <<endl;
cerr << " save package changelogs; copy changelog entries" <<endl;
cerr << " newer than seconds since the Epoch, and also" <<endl;
cerr << " one preceding entry (if any)" <<endl;
}


struct rec {
const char *rpm;
const char *srpm;
};

static
int recCmp(const void *rec1_, const void *rec2_)
{
const struct rec *rec1 = (const struct rec *) rec1_;
const struct rec *rec2 = (const struct rec *) rec2_;
int cmp = strcmp(rec1->srpm, rec2->srpm);
if (cmp)
return cmp;
return strcmp(rec1->rpm, rec2->rpm);
}


int main(int argc, char ** argv)
{
string rpmsdir;
string pkglist_path;
struct dirent **dirEntries;
int entry_no, entry_cur;
char *op_dir;
char *op_suf;
char *op_index = NULL;
char *op_usefulFiles = NULL;
char *op_update = NULL;
int i;
long /* time_t */ changelog_since = 0;
bool fullFileList = false;
bool noScan = false;
bool progressBar = false;
const char *pkgListSuffix = NULL;
bool pkgListAppend = false;

putenv((char *)"LC_ALL="); // Is this necessary yet (after i18n was supported)?
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--index") == 0) {
i++;
if (i < argc) {
op_index = argv[i];
} else {
cerr << "genpkglist: filename missing for option --index"<<endl;
exit(1);
}
} else if (strcmp(argv[i], "--info") == 0) {
i++;
if (i < argc) {
op_update = argv[i];
} else {
cerr << "genpkglist: filename missing for option --info"<<endl;
exit(1);
}
} else if (strcmp(argv[i], "--useful-files") == 0) {
i++;
if (i < argc) {
op_usefulFiles = argv[i];
} else {
cerr << "genpkglist: filename missing for option --useful-files"<<endl;
return 1;
}
} else if (strcmp(argv[i], "--changelog-since") == 0) {
i++;
if (i < argc) {
changelog_since = atol(argv[i]);
} else {
cerr << "genpkglist: argument missing for option --changelog-since" <<endl;
exit(1);
}
} else if (strcmp(argv[i], "--bloat") == 0) {
fullFileList = true;
} else if (strcmp(argv[i], "--no-scan") == 0) {
noScan = true;
} else if (strcmp(argv[i], "--progress") == 0) {
progressBar = true;
} else if (strcmp(argv[i], "--append") == 0) {
pkgListAppend = true;
} else if (strcmp(argv[i], "--meta") == 0) {
i++;
if (i < argc) {
pkgListSuffix = argv[i];
} else {
cerr << "genpkglist: argument missing for option --meta"<<endl;
exit(1);
}
} else if (strcmp(argv[i], "--cachedir") == 0) {
i++;
if (i < argc) {
_config->Set("Dir::Cache", argv[i]);
} else {
cerr << "genpkglist: argument missing for option --cachedir"<<endl;
exit(1);
}
} else {
break;
}
}
if (argc - i > 0)
op_dir = argv[i++];
else {
usage();
exit(1);
}
if (argc - i > 0)
op_suf = argv[i++];
else {
usage();
exit(1);
}
if (argc != i) {
usage();
}

map<string,UpdateInfo> updateInfo;
if (op_update) {
if (!loadUpdateInfo(op_update, updateInfo)) {
cerr << "genpkglist: error reading update info from file " << op_update << endl;
_error->DumpErrors();
exit(1);
}
}

FILE *idxfp = NULL;
if (op_index) {
idxfp = fopen(op_index, "w+");
if (!idxfp) {
cerr << "genpkglist: could not open " << op_index << " for writing";
perror("");
exit(1);
}
}

{
char cwd[PATH_MAX];

if (getcwd(cwd, PATH_MAX) == 0)
{
cerr << argv[0] << ": " << strerror(errno) << endl;
exit(1);
}
if (*op_dir != '/') {
rpmsdir = string(cwd) + "/" + string(op_dir);
} else {
rpmsdir = string(op_dir);
}
}
pkglist_path = string(rpmsdir);
rpmsdir = rpmsdir + "/RPMS." + string(op_suf);

string dirtag = "RPMS." + string(op_suf);

if (chdir(rpmsdir.c_str()) != 0 ||
(entry_no = scandir(".", &dirEntries, selectRPMs, alphasort)) < 0)
{
cerr << "genpkglist: " << rpmsdir << ": " << strerror(errno) << endl;
return 1;
}

if (pkgListSuffix != NULL)
pkglist_path = pkglist_path + "/base/pkglist." + pkgListSuffix;
else
pkglist_path = pkglist_path + "/base/pkglist." + op_suf;

FD_t outfd;
if (pkgListAppend == true && FileExists(pkglist_path)) {
outfd = Fopen(pkglist_path.c_str(), "a");
} else {
unlink(pkglist_path.c_str());
outfd = Fopen(pkglist_path.c_str(), "w+");
}
if (!outfd) {
cerr << "genpkglist: error creating file " << pkglist_path << ": "
<< strerror(errno) << endl;
return 1;
}

set<string> usefulFiles;
if (op_usefulFiles) {
ifstream strm(op_usefulFiles);
if (!strm) {
cerr << "genpkglist: cannot open " << op_usefulFiles <<endl;
return 1;
}
string line;
while (std::getline(strm, line))
usefulFiles.insert(line);
}

struct rec *recs = NULL;
int nrec = 0;

if (entry_no > 0)
recs = new struct rec[entry_no];

for (entry_cur = 0; entry_cur < entry_no; entry_cur++) {

if (progressBar)
simpleProgress(entry_cur + 1, entry_no);

const char *rpm = dirEntries[entry_cur]->d_name;

Header h = readHeader(rpm);
if (h == NULL) {
cerr << "genpkglist: " << rpm << ": cannot read package header" << endl;
return 1;
}

const char *srpm = getStringTag(h, RPMTAG_SOURCERPM);
if (srpm == NULL) {
cerr << "genpkglist: " << rpm << ": invalid binary package" << endl;
headerFree(h);
return 1;
}
srpm = strdup(srpm);
if (srpm == NULL) {
cerr << "genpkglist: " << strerror(errno) << endl;
return 1;
}

recs[nrec].rpm = rpm;
recs[nrec].srpm = srpm;
nrec++;

if (!(fullFileList || noScan)) {
findDepFiles(h, usefulFiles, RPMTAG_REQUIRENAME);
findDepFiles(h, usefulFiles, RPMTAG_PROVIDENAME);
findDepFiles(h, usefulFiles, RPMTAG_CONFLICTNAME);
findDepFiles(h, usefulFiles, RPMTAG_OBSOLETENAME);
}

headerFree(h);
}

if (nrec > 1)
qsort(recs, nrec, sizeof(recs[0]), recCmp);

CachedMD5 md5cache(string(op_dir) + string(op_suf), "genpkglist");

for (int reci = 0; reci < nrec; reci++) {

if (progressBar)
simpleProgress(reci + 1, nrec);

const char *rpm = recs[reci].rpm;

struct stat sb;
if (stat(rpm, &sb) < 0) {
cerr << "genpkglist: " << rpm << ": " << strerror(errno) << endl;
return 1;
}

Header h = readHeader(rpm);
if (h == NULL) {
cerr << "genpkglist: " << rpm << ": cannot read package header" << endl;
return 1;
}

Header newHeader = headerNew();
copyTags(h, newHeader, numTags, tags);
if (!fullFileList)
copyStrippedFileList(h, newHeader, usefulFiles);
else {
copyTag(h, newHeader, RPMTAG_BASENAMES);
copyTag(h, newHeader, RPMTAG_DIRNAMES);
copyTag(h, newHeader, RPMTAG_DIRINDEXES);
}
if (changelog_since > 0)
copyChangelog(h, newHeader, changelog_since);

addAptTags(newHeader, dirtag.c_str(), rpm, sb.st_size);
if (op_update)
addInfoTags(newHeader, rpm, updateInfo);

char md5[34];
md5cache.MD5ForFile(rpm, sb.st_mtime, md5);
addStringTag(newHeader, CRPMTAG_MD5, md5);

if (idxfp) {
const char *srpm = getStringTag(h, RPMTAG_SOURCERPM);
const char *name = getStringTag(h, RPMTAG_NAME);
if (srpm && name)
fprintf(idxfp, "%s %s\n", srpm, name);
}

headerWrite(outfd, newHeader, HEADER_MAGIC_YES);

headerFree(newHeader);
headerFree(h);
}

Fclose(outfd);

return 0;
}
apt-repo-tools-0.6.0.17/gensrclist.cc000064400000000000000000000164221230743126200173170ustar00rootroot00000000000000/*
* $Id: gensrclist.cc,v 1.8 2003/01/30 17:18:21 niemeyer Exp $
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <alloca.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <rpm/rpmlib.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <assert.h>

#include <map>
#include <list>
#include <vector>
#include <iostream>

#include <apt-pkg/error.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/configuration.h>

#include "rapt-compat.h"
#include "crpmtag.h"
#include "cached_md5.h"
#include "genutil.h"

using namespace std;

raptTag tags[] = {
RPMTAG_NAME,
RPMTAG_EPOCH,
RPMTAG_VERSION,
RPMTAG_RELEASE,
RPMTAG_GROUP,
RPMTAG_ARCH,
RPMTAG_PACKAGER,
RPMTAG_SOURCERPM,
RPMTAG_SIZE,
RPMTAG_VENDOR,
RPMTAG_OS,

RPMTAG_DESCRIPTION,
RPMTAG_SUMMARY,
/*RPMTAG_HEADERI18NTABLE*/ HEADER_I18NTABLE,

RPMTAG_REQUIREFLAGS,
RPMTAG_REQUIRENAME,
RPMTAG_REQUIREVERSION
};
int numTags = sizeof(tags) / sizeof(tags[0]);

static
void readIndex(FILE *fp, map<string, vector<const char *> > &table)
{
char line[512];
while (fgets(line, sizeof(line), fp)) {
line[strlen(line)-1] = '\0'; // trim newline
char *val = strchr(line, ' ');
assert(val);
*val++ = '\0';
const char *srpm = line;
const char *rpm = strdup(val);
assert(rpm);
table[srpm].push_back(rpm);
}
}


void usage()
{
cerr << "gensrclist " << VERSION << endl;
cerr << "usage: gensrclist [<options>] <dir> <suffix> <srpm index>" << endl;
cerr << "options:" << endl;
// cerr << " --mapi ???????????????????" << endl;
cerr << " --flat use a flat directory structure, where RPMS and SRPMS"<<endl;
cerr << " are in the same directory level"<<endl;
cerr << " --meta <suffix> create source package file list with given suffix" << endl;
cerr << " --append append to the source package file list, don't overwrite" << endl;
cerr << " --progress show a progress bar" << endl;
cerr << " --cachedir=DIR use a custom directory for package md5sum cache"<<endl;
}

int main(int argc, char ** argv)
{
char buf[300];
char cwd[PATH_MAX];
string srpmdir;
struct dirent **dirEntries;
int i;
int entry_no, entry_cur;
bool mapi = false;
bool progressBar = false;
bool flatStructure = false;
char *arg_dir, *arg_suffix, *arg_srpmindex;
const char *srcListSuffix = NULL;
bool srcListAppend = false;

putenv((char *)"LC_ALL="); // Is this necessary yet (after i18n was supported)?
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--mapi") == 0) {
mapi = true;
} else if (strcmp(argv[i], "--flat") == 0) {
flatStructure = true;
} else if (strcmp(argv[i], "--progress") == 0) {
progressBar = true;
} else if (strcmp(argv[i], "--append") == 0) {
srcListAppend = true;
} else if (strcmp(argv[i], "--meta") == 0) {
i++;
if (i < argc) {
srcListSuffix = argv[i];
} else {
cerr << "gensrclist: argument missing for option --meta"<<endl;
exit(1);
}
} else if (strcmp(argv[i], "--cachedir") == 0) {
i++;
if (i < argc) {
_config->Set("Dir::Cache", argv[i]);
} else {
cerr << "genpkglist: argument missing for option --cachedir"<<endl;
exit(1);
}
} else {
break;
}
}
if (argc - i == 3) {
arg_dir = argv[i++];
arg_suffix = argv[i++];
arg_srpmindex = argv[i++];
}
else {
usage();
exit(1);
}

map<string, vector<const char *> > srpm2rpms;
FILE *fp = fopen(arg_srpmindex, "r");
if (fp == NULL) {
cerr << "gensrclist: " << arg_srpmindex << ": " << strerror(errno) << endl;
return 1;
}
readIndex(fp, srpm2rpms);
fclose(fp);

if(getcwd(cwd, PATH_MAX) == 0)
{
cerr << argv[0] << ": " << strerror(errno) << endl;
exit(1);
}

if (*arg_dir != '/') {
strcpy(buf, cwd);
strcat(buf, "/");
strcat(buf, arg_dir);
} else
strcpy(buf, arg_dir);

strcat(buf, "/SRPMS.");
strcat(buf, arg_suffix);

srpmdir = "SRPMS." + string(arg_suffix);
#ifdef OLD_FLATSCHEME
if (flatStructure) {
// add the last component of the directory to srpmdir
// that will cancel the effect of the .. used in sourcelist.cc
// when building the directory from where to fetch srpms in apt
char *prefix;
prefix = strrchr(arg_dir, '/');
if (prefix == NULL)
prefix = arg_dir;
else
prefix++;
if (*prefix != 0 && *(prefix+strlen(prefix)-1) == '/')
srpmdir = string(prefix) + srpmdir;
else
srpmdir = string(prefix) + "/" + srpmdir;
}
#else
if (!flatStructure)
srpmdir = "../"+srpmdir;
#ifndef REMOVE_THIS_SOMEDAY
/* This code is here just so that code in rpmsrcrecords.cc in versions
* prior to 0.5.15cnc4 is able to detect if that's a "new" style SRPM
* directory scheme, or an old style. Someday, when 0.5.15cnc4 will be
* history, this code may be safely removed. */
else
srpmdir = "./"+srpmdir;
#endif
#endif

entry_no = scandir(buf, &dirEntries, selectRPMs, alphasort);
if (entry_no < 0) {
cerr << "gensrclist: error opening directory " << buf << ": "
<< strerror(errno) << endl;
return 1;
}

if(chdir(buf) != 0)
{
cerr << argv[0] << ":" << strerror(errno) << endl;
exit(1);
}

if (srcListSuffix != NULL)
sprintf(buf, "%s/srclist.%s", cwd, srcListSuffix);
else
sprintf(buf, "%s/srclist.%s", cwd, arg_suffix);

FD_t outfd;
if (srcListAppend == true && FileExists(buf)) {
outfd = Fopen(buf, "a");
} else {
unlink(buf);
outfd = Fopen(buf, "w+");
}
if (!outfd) {
cerr << "gensrclist: error creating file " << buf << ": "
<< strerror(errno) << endl;
return 1;
}

CachedMD5 md5cache(string(arg_dir) + string(arg_suffix), "gensrclist");

for (entry_cur = 0; entry_cur < entry_no; entry_cur++) {

if (progressBar)
simpleProgress(entry_cur + 1, entry_no);

const char *fname = dirEntries[entry_cur]->d_name;

struct stat sb;
if (stat(fname, &sb) < 0) {
cerr << "gensrclist: " << fname << ": " << strerror(errno) << endl;
return 1;
}

Header h = readHeader(fname);
if (h == NULL) {
cerr << "gensrclist: " << fname << ": cannot read package header" << endl;
return 1;
}

Header newHeader = headerNew();
copyTags(h, newHeader, numTags, tags);
addAptTags(newHeader, srpmdir.c_str(), fname, sb.st_size);

char md5[34];
md5cache.MD5ForFile(fname, sb.st_mtime, md5);
addStringTag(newHeader, CRPMTAG_MD5, md5);

map<string, vector<const char *> >::const_iterator I = srpm2rpms.find(fname);
if (I != srpm2rpms.end()) {
const vector<const char *> &rpmv = I->second;
assert(rpmv.size() > 0);
headerAddEntry(newHeader, CRPMTAG_BINARY, RPM_STRING_ARRAY_TYPE,
&rpmv[0], rpmv.size());
headerWrite(outfd, newHeader, HEADER_MAGIC_YES);
}
else if (!mapi) { // write anyway
headerWrite(outfd, newHeader, HEADER_MAGIC_YES);
}

headerFree(newHeader);
headerFree(h);
}

Fclose(outfd);

return 0;
}

// vim:sts=3:sw=3
apt-repo-tools-0.6.0.17/genutil.h000064400000000000000000000060511230743126200164500ustar00rootroot00000000000000
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

static inline
bool endswith(const char *str, const char *suffix)
{
size_t len1 = strlen(str);
size_t len2 = strlen(suffix);
if (len1 < len2)
return false;
str += (len1 - len2);
if (strcmp(str, suffix))
return false;
return true;
}

static
#if defined(__APPLE__) || defined(__FREEBSD__)
int selectRPMs(struct dirent *ent)
#else
int selectRPMs(const struct dirent *ent)
#endif
{
const char *b = ent->d_name;
return (*b != '.' && endswith(b, ".rpm"));
}

static
void simpleProgress(unsigned int current, unsigned int total)
{
bool erase = (current > 1);
if (erase) {
putc('\b', stdout);
putc('\b', stdout);
}
int width = 0;
unsigned int n = total;
while (n) {
n /= 10;
width++;
if (erase) {
putc('\b', stdout);
putc('\b', stdout);
}
}
printf(" %*u/%*u", width, current, width, total);
fflush(stdout);
}

#if RPM_VERSION >= 0x040100
#include <rpm/rpmts.h>
#endif

static
Header readHeader(const char *path)
{
FD_t fd = Fopen(path, "r");
if (fd == NULL)
return NULL;
Header h = NULL;
#if RPM_VERSION >= 0x040100
static rpmts ts = NULL;
if (ts == NULL) {
rpmReadConfigFiles(NULL, NULL);
ts = rpmtsCreate();
assert(ts);
rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
}
int rc = rpmReadPackageFile(ts, fd, dirEntries[entry_cur]->d_name, &h);
bool ok = (rc == RPMRC_OK || rc == RPMRC_NOTTRUSTED || rc == RPMRC_NOKEY);
#else
int rc = rpmReadPackageHeader(fd, &h, NULL, NULL, NULL);
bool ok = (rc == 0);
#endif
Fclose(fd);
if (ok)
return h;
return NULL;
}

#if RPM_VERSION >= 0x040000
// No prototype from rpm after 4.0.
extern "C"
int headerGetRawEntry(Header h, raptTag tag, raptTagType * type,
raptTagData p, raptTagCount *c);
#endif

static
void copyTag(Header h1, Header h2, raptTag tag)
{
raptTagType type;
raptTagCount count;
raptTagData data;
// Copy raw entry, so that internationalized strings
// will get copied correctly.
int rc = headerGetRawEntry(h1, tag, &type, &data, &count);
if (rc == 1) {
headerAddEntry(h2, tag, type, data, count);
headerFreeData(data, (rpmTagType)type);
}
}

static
void copyTags(Header h1, Header h2, int tagc, raptTag tagv[])
{
for (int i = 0; i < tagc; i++)
copyTag(h1, h2, tagv[i]);
}

static inline
int addStringTag(Header h, raptTag tag, const char *str)
{
return headerAddEntry(h, tag, RPM_STRING_TYPE, str, 1);
}

static inline
const char *getStringTag(Header h, raptTag tag)
{
raptTagType type;
raptTagCount count;
raptTagData data;
int rc = headerGetEntry(h, tag, &type, &data, &count);
if (rc == 1) {
assert(type == RPM_STRING_TYPE && count == 1);
return (const char *)data;
}
return NULL;
}

static
void addAptTags(Header h, const char *d, const char *b, unsigned int st_size)
{
raptInt size[1] = { st_size };
addStringTag(h, CRPMTAG_DIRECTORY, d);
addStringTag(h, CRPMTAG_FILENAME, b);
headerAddEntry(h, CRPMTAG_FILESIZE, RPM_INT32_TYPE, size, 1);
}

apt-repo-tools-0.6.0.17/pkglist-query.cc000064400000000000000000000021001230743126200177460ustar00rootroot00000000000000#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <rpm/rpmlib.h>

int main(int argc, char *argv[])
{
const char *progname = argv[0];
if (argc < 3) {
fprintf(stderr, "Usage: %s <format> <pkglist>...\n", progname);
return 2;
}
const char *format = argv[1];
int rc = 0;
const char *pkglist;
int ix = 2;
while ((pkglist = argv[ix++]) != NULL) {
FD_t Fd = Fopen(pkglist, "r.ufdio");
if (Ferror(Fd)) {
fprintf(stderr, "%s: %s: %s\n", progname, pkglist, Fstrerror(Fd));
rc = 1;
continue;
}
Header h;
while ((h = headerRead(Fd, HEADER_MAGIC_YES)) != NULL) {
const char *err = "unknown error";
#ifdef RPM_HAVE_HEADERFORMAT
char *str = headerFormat(h, format, &err);
#else
char *str = headerSprintf(h, format, rpmTagTable, rpmHeaderFormats, &err);
#endif
if (str == NULL) {
rc = 1;
fprintf(stderr, "%s: %s: %s\n", progname, pkglist, err);
}
else {
fputs(str, stdout);
free(str);
}
headerFree(h);
}
Fclose(Fd);
}
return rc;
}

// ex:set ts=8 sts=4 sw=4 noet:
apt-repo-tools-0.6.0.17/rapt-compat.h000064400000000000000000000001731230743126200172270ustar00rootroot00000000000000
typedef int raptInt;
typedef int raptTag;
typedef int raptTagType;
typedef int raptTagCount;
typedef void * raptTagData;

 
projeto & código: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
mantenedor atual: Michael Shigorin
mantenedor da tradução: Fernando Martini aka fmartini © 2009