Date: Fri, 12 Nov 1999 07:05:32 +1100 From: Peter Jeremy <peter.jeremy@alcatel.com.au> To: ctm-announce@FreeBSD.ORG Subject: Recovering from ports-cur and src-cur problems Message-ID: <99Nov12.065937est.40322@border.alcanet.com.au>
index | next in thread | raw e-mail
[-- Attachment #1 --]
This mail is being posted with Chuck Robey's OK. This list is still
intended to be low volume and discussions should off-list.
I suspect this is somewhat later than Chuck would have liked, but
attached is a perl script I knocked up a couple of months ago to
let me delete sections from a CTM delta. With a bit of hacking,
those of you who have applied the `wrong' version of the duplicated
ports-cur or cvs-cur deltas should be able to recover fairly easily
(assuming you still have a copy of the delta you applied, or at
least a list of the files).
In its current form, it's designed to turn chop bits out of a
directory full of CTM deltas and leave the result as valid CTM deltas
in a second directory. (This lets me keep a CVS subtree on a second
system without having to build my own deltas).
By changing the code that selects whether to keep the delta or not
(the statement following the comment #XXXXXX), you could use it to
chop the already applied bits out of your delta and get CTM to apply
the rest. (My [untested] solution would be to build an array of files
that were in the first delta and skip these when processing the second
delta. The result will be a CTM file (without the .ctm_status file)
which ctm should be able to apply).
There's no documentation because this was never intended for public
consumption. RTSL. (I will attempt to answer questions off-list).
WARNING: The output files generated by this script look _identical_ to
the original CTM deltas as far as ctm(8) is concerned. This script
worked for me. No warranty etc etc. I accept no responsibility for
bullet holes in your feet.
Peter
--
Peter Jeremy (VK2PJ) peter.jeremy@alcatel.com.au
Alcatel Australia Limited
41 Mandible St Phone: +61 2 9690 5019
ALEXANDRIA NSW 2015 Fax: +61 2 9690 5982
[-- Attachment #2 --]
#!/usr/bin/perl -w
#
# Strip CTM archives down to the bits we have locally on vk2pj:
# CVSROOT (without CVSROOT/commitlogs) and src
use POSIX ":sys_wait_h";
($#ARGV == 1) || die "Usage: $0 indir outdir\n";
($indir, $outdir) = @ARGV;
$SIG{PIPE} = 'IGNORE';
# Load and sort files from both input directories
(opendir(DIR, $indir) &&
(@indir = readdir(DIR)) &&
closedir(DIR)) || die "$0: Failed to load $indir: $!\n";
-d $outdir || mkdir($outdir, 0777);
(opendir(DIR, $outdir) &&
(@outdir = readdir(DIR)) &&
closedir(DIR)) || die "$0: Failed to load $outdir: $!\n";
@indir = sort(@indir);
@outdir{@outdir} = (1) x @outdir;
# Locate files in $indir that aren't in $outdir and process them
foreach $file (@indir) {
($file =~ /^\./) && next;
defined($outdir{$file}) ||
&convert($indir . '/' . $file, $outdir . '/' . $file);
}
# convert(infile, outfile) - Convert a CTM delta `infile' to a cutdown
# version in `outfile'. Die if anything goes wrong.
sub convert {
local($infile, $outfile) = @_;
local($pid, $_, $key, @args, $name, $len);
warn "Creating $outfile\n";
# Arrange to write the output to $outfile
open(STDOUT, '>' . $outfile) || die "$0: Failed to open $outfile: $!\n";
if ($infile =~ /\.gz/) {
# Compressed input re/write via gzip
# warn "Input compressed\n";
open(IN, 'gzcat ' . $infile . '|') ||
die "$0: Failed to open $infile: $!\n";
# warn "started gzcat on input\n";
open(STDOUT, '| gzip') || die "$0: Failed to fork gzip: $!\n";
# warn "started gzip on output\n";
} else {
open(IN, $infile) || die "$0: Failed to open $infile: $!\n";
}
# And insert md5 into the output
open(STDOUT, '| /sbin/md5 -p') || die "$0: Failed to fork md5: $!\n";
# And another md5 to validate input
(pipe(RD1, MD5_CHECK) && pipe(MD5_OUT, WR2)) ||
die "$0: Pipes failed: $!\n";
defined($pid = fork) || die "$0: fork() failed: $!\n";
if (!$pid) { # child
open(STDOUT, '>&WR2') || die "$0: Failed to dup stdout: $!\n";
open(STDIN, '>&RD1') || die "$0: Failed to dup stdin: $!\n";
exec '/sbin/md5';
exit 1;
}
close(RD1);
close(WR2);
# All FDs ready: Read the CTM file from IN, copy it to MD5_CHECK
# (excluding the trailing MD5 sum), chop off the bits we don't want
# and forward to STDOUT (which is piped through various processes
# to the output file)
while (<IN>) {
/^CTM/ || die "$0: Phase error in $infile: $!";
($key, $name, @args) = split;
$len = 0;
if ($key eq 'CTMFM') {
$len = $args[4] + 1;
} elsif ($key eq 'CTMFS' || $key eq 'CTMFN') {
$len = $args[5] + 1;
} elsif ($key eq 'CTM_BEGIN') {
print(MD5_CHECK $_) || die "$0: md5 check error: $!";
print($_) || die "$0: md5 check error: $!";
next;
} elsif ($key eq 'CTM_END') {
print(MD5_CHECK 'CTM_END ') || die "$0: md5 check error: $!";
close(MD5_CHECK) || die "$0: md5 check error: $!";
defined($md5 = <MD5_OUT>) || die "$0: Error reading md5 sum: $!";
chop($md5);
($md5 eq $name) || die "$0: md5 mismatch: $md5 != $name\n";
print 'CTM_END ';
last;
}
($len > 0) && (read(IN, $_, $len, length($_)) ||
die "$0: read error: $!\n");
print(MD5_CHECK $_) || die "$0: md5 check error: $!";
#XXXXX Select what pieces to pass through here.
($name =~ m:^src/: ||
($name =~ m:^CVSROOT/: && $name !~ m:^CVSROOT/commitlogs/:) ||
$name eq '.ctm_status') &&
(print($_) || die "$0: write error: $!");
}
close(MD5_OUT) || die "$0: Failed to close md5 check: $!";
close(STDOUT) || die "$0: Failed to close output: $!";
close(IN) || die "$0: Failed to close input: $!";
# Dispose of zombies
do {
$kid = waitpid(-1,&WNOHANG);
} until $kid == -1;
}
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?99Nov12.065937est.40322>
