Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Feb 1998 20:25:42 +0100
From:      Stefan Esser <se@FreeBSD.ORG>
To:        Warner Losh <imp@village.org>, "Jordan K. Hubbard" <jkh@time.cdrom.com>
Cc:        ports@FreeBSD.ORG, Stefan Esser <se@FreeBSD.ORG>
Subject:   Re: make install
Message-ID:  <19980222202542.44809@mi.uni-koeln.de>
In-Reply-To: <19980222105848.49897@mi.uni-koeln.de>; from Stefan Esser on Sun, Feb 22, 1998 at 10:58:48AM %2B0100
References:  <23951.888111289@time.cdrom.com> <199802220424.VAA27120@harmony.village.org> <19980222105848.49897@mi.uni-koeln.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On 1998-02-22 10:58 +0100, Stefan Esser <se@FreeBSD.ORG> wrote:
> As part of the install target (but not reinstall ?) the default
> behaviour should be:
> 
> - abort with explanatory message (incl. file names), if .conflicts 
>   is not empty
> - delete files mentioned in .dodelete
> - rename files mentioned in .dopreserve 
>   (append suffix, e.g. OLD or even OLD.$oldrev or OLD.$timestamp)
> 
> In order to have this to work with packages, we need to implement
> a similar functionalty in pkg_add. There could be hints in +CONTENTS,
> using the same tags as might be added to PLIST for the port.

Following up to my own mail:

During a long compilation, I wrote the following Perl script,
which compares a new PLIST against the old +CONTENTS and checks
MD5s as proposed in my last mail.

This is just a prototype implementation hacked together (and
tested :) in one hour. There should be a second (much simpler)
one, which deletes all files listed in "work/.saved" and then
the *old* package registration information of the version that 
has been replaced.

Comments, please ...

# --- cut here ---- 8< ---- cut here ---- 8< ---- cut here ---- 8< ---
#!/usr/bin/perl
#
# Prepare port update
#
# Usage: prepare-install PREFIX DBDIR PORTDIR
#
# These parameters can easily been obtained in a Makefile,
# the OLDDIR is the result of a "ls -t $name-* | head -1"
# with $name easily constructed from available information.
#

$PREFIX = $ARGV[0] || "/usr/local";
$OLDDIR = $ARGV[1] || "/var/db/pkg/kdebase-3.1b";
$NEWDIR = $ARGV[2] || "/usr/ports/x11/kdebase";

# print "$OLDDIR/+CONTENTS\n";
open(CONTENTS, "<$OLDDIR/+CONTENTS");
@OLDCONTENTS = <CONTENTS>;
close(CONTENTS);

# print "$NEWDIR/pkg/PLIST\n";
open(PLIST, "<$NEWDIR/pkg/PLIST");
@NEWPLIST = <PLIST>;
close(PLIST);

# ------------------------------------------------------------------------

for (@OLDCONTENTS)
{
    chop;
    $filename = $_, $OLDFILE{$_} = 1, next	unless m/^\@/;
    $OLDMD5{$filename} = $1, next		if m/^\@comment MD5:(.+)/;
    push(@RMDIR, $1), next			if m/^\@dirrm (.+)/;
}

for (@NEWPLIST)
{
    chop;
    next					if m/^@/;
    $BOTH{$_} = 1, next				if ($OLDFILE{$_});
    $name = "$PREFIX/$_";
    push(@CONFLICTS, $name)			if -e "$name";
}

# ------------------------------------------------------------------------

if (@CONFLICTS)
{
    print STDERR "Conflicts:\n";
    for (@CONFLICTS)
    {
	print STDERR "$_\n";
    }
    exit(1);
}

for (sort keys %OLDFILE)
{
    $name = "$PREFIX/$_";
    next					 unless -e $name;
    `md5 $name` =~ m/^MD5 \(.+\) = ([0-9a-f]+)/;
    $md5 = $1;
#print ("$name: MD5 = $md5, should be $OLDMD5{$_}\n") if ($md5 ne $OLDMD5{$_});
    push(@MODIFIED, $_), next			if ($md5 ne $OLDMD5{$_});
    push(@DELETE, $_)				unless ($BOTH{$_});
}

# ------------------------------------------------------------------------

$suffix = ".OLD";
$suffix = "-$1.OLD"				if $OLDDIR =~ m/-([^-]+)/;
# remove previous line, if you don't want backup files to have versions

for (@DELETE)
{
    $name = "$PREFIX/$_";
    print "rm -f $name\n";
}

# preserve modified files
open(SAVED, ">$NEWDIR/work/.saved");
for (@MODIFIED)
{
    $name = "$PREFIX/$_";
    print "mv $name $name$suffix\n";
    print SAVED ("$name$suffix\n");
}
close(SAVED);

# try to remove directories, in case they are empty now
for (@RMDIR)
{
    $name = "$PREFIX/$_";
    print "rmdir $name 2>/dev/null\n";
}
exit(0);
# --- cut here ---- 8< ---- cut here ---- 8< ---- cut here ---- 8< ---

Regards, STefan

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980222202542.44809>