From: Alexey Tourbin <at@altlinux.ru>
To: ALT Devel discussion list <devel@altlinux.org>
Subject: [devel] Re: librpm payload
Date: Sun, 11 Sep 2005 21:06:44 +0400
Message-ID: <20050911170644.GE3290@solemn.turbinal.org> (raw)
In-Reply-To: <20050905034357.GM3539@solemn.turbinal.org>
[-- Attachment #1.1: Type: text/plain, Size: 1814 bytes --]
On Mon, Sep 05, 2005 at 07:43:57AM +0400, Alexey Tourbin wrote:
> Как читать поток cpio, я разобрался. Теперь дальше, как парсить cpio?
> У него какой-то хитрый padding (см. TODO). Как libmagic подключить --
> вроде ясно, magic_buffer().
>
> Что-то такое есть в rpm-4_0-4.0.4/lib/{cpio,fsm}.{c,h}, но им
> воспользоваться очень проблемно.
Нет, задолбало на Си писать. Это контрпродуктивно. Можно что-нибудь
сделать, а можно сидеть и пейсать на Си. Ну его в баню.
Написал на шелле, с кешированием для каталогов. Для робота это важно --
очень долго (с распаковкой всех rpm'ов) только один раз будет работать.
$ ./rpmfile -h
Usage:
rpmfile [-h] [*FILE*...] [*DIR*...]
$ ./rpmfile ~/build/repo/i586/RPMS.hasher/qa-robot-0.2-alt1.noarch.rpm
/usr/bin/bugs 100755 Bourne shell script text executable
/usr/bin/csv2tab 100755 perl script text executable
...
$ ./rpmfile ~/build/repo/i586/RPMS.hasher |sort -t$'\t' -k1,1 -u
libsqlite3 /usr/lib/libsqlite3.so.0 120777 symbolic link to `libsqlite3.so.0.8.6'
libsqlite3-devel /usr/include/sqlite3.h 100644 ASCII C program text
...
$
То есть если "дампить" каталог, то впереди добавляется ещё подно поле --
имя пакета. Правильнее было бы добавлять не имя пакета, а собственно
имя файла, но мне сейчас нужнее имя пакета.
А кеширование работает так:
$ rm -rf ~/tmp/tmp
$ mkdir -p ~/tmp/tmp
$ time workdir=~/tmp/tmp ./rpmfile ~/build/repo/i586/RPMS.hasher >/dev/null
workdir=~/tmp/tmp ./rpmfile ~/build/repo/i586/RPMS.hasher > /dev/null 16,70s user 4,81s system 95% cpu 22,606 total
$ time workdir=~/tmp/tmp ./rpmfile ~/build/repo/i586/RPMS.hasher >/dev/null
workdir=~/tmp/tmp ./rpmfile ~/build/repo/i586/RPMS.hasher > /dev/null 1,46s user 0,22s system 99% cpu 1,685 total
$
Трюк с paste(1) -- по моему, красиво. :)
[-- Attachment #1.2: rpmfile --]
[-- Type: text/plain, Size: 1734 bytes --]
#!/bin/sh -ef
export LC_ALL=C
dump_file()
{
rpm -qp --qf '[%{FILENAMES}\t%{FILEMODES:octal}\n]' "$@" >files
if [ -d d ]; then chmod -Rf u+rwX d; rm -rf d; fi
rpm2cpio "$@" |(mkdir d; cd d; cpio -idmu --quiet)
awk -F'\t' '{printf"d/%s\0",$1}' files |xargs -r0 file -b >types
paste files types
}
dump_dir()
{
local d="$1"; shift
packages "$d" >packages
sort -t$'\t' -o packages -u -k1,1 packages
mkdir -p c
while IFS=$'\t' read p v f _; do
b="${f%%.rpm}"
[ -f c/"$b" ] || dump_file "$d/$f" >c/"$b"
awk -v p="$p" '{print p"\t"$0}' c/"$b"
done <packages
}
while getopts h opt; do
case "$opt" in
h) pod2usage --exit=0 "$0"; exit 0 ;;
*) pod2usage --exit=2 "$0"; exit 2 ;;
esac
done
shift "$((OPTIND-1))"
if [ -z "$workdir" ]; then
atexit() { rc=$?; trap - EXIT; rm -rf "$workdir"; exit $rc; }
workdir="$(mktemp -d -t "${0##*/}.XXXXXXXX")"
trap atexit EXIT HUP INT QUIT PIPE TERM
export workdir
fi
if [ -z "$*" ]; then
: ${sisyphus:=/raid/ALT/Sisyphus}
set -- "$sisyphus"/files/i586/RPMS
fi
for arg; do
arg="$(readlink -ev "${arg:?}")"
cd "${workdir:?}"
if [ -f "$arg" ]; then
dump_file "$arg"
else
dump_dir "$arg"
fi
cd -
done
: <<'__EOF__'
=head1 NAME
rpmfile - list file modes and types in RPM packages
=head1 SYNOPSIS
B<rpmfile> [B<-h>] [I<FILE>...] [I<DIR>...]
=head1 AUTHOR
Written by Alexey Tourbin <at@altlinux.org>.
=head1 COPYING
Copyright (c) 2005 Alexey Tourbin, ALT Linux Team.
This is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
=head1 SEE ALSO
rpm(8),
rpm2cpio(8),
file(1)
=cut
__EOF__
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2005-09-11 17:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-02 20:14 [devel] " Alexey Tourbin
2005-09-02 21:00 ` Dmitry V. Levin
2005-09-05 3:43 ` [devel] " Alexey Tourbin
2005-09-05 9:09 ` Sergey Vlasov
2005-09-11 17:06 ` Alexey Tourbin [this message]
2005-09-11 22:14 ` Dmitry V. Levin
2005-09-12 3:48 ` Alexey Tourbin
2005-09-12 10:28 ` Dmitry V. Levin
2005-09-13 8:51 ` [devel] rpmfile Alexey Tourbin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050911170644.GE3290@solemn.turbinal.org \
--to=at@altlinux.ru \
--cc=devel@altlinux.org \
--cc=devel@altlinux.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Team development discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
public-inbox-index devel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git