[csw-devel] SF.net SVN: gar:[14323] csw/mgar/gar/v2
dmichelsen at users.sourceforge.net
dmichelsen at users.sourceforge.net
Mon Apr 18 17:16:52 CEST 2011
Revision: 14323
http://gar.svn.sourceforge.net/gar/?rev=14323&view=rev
Author: dmichelsen
Date: 2011-04-18 15:16:52 +0000 (Mon, 18 Apr 2011)
Log Message:
-----------
mGAR v2: Activate new pcopy merging instead of pax
Modified Paths:
--------------
csw/mgar/gar/v2/gar.mk
Added Paths:
-----------
csw/mgar/gar/v2/bin/pcopy
Added: csw/mgar/gar/v2/bin/pcopy
===================================================================
--- csw/mgar/gar/v2/bin/pcopy (rev 0)
+++ csw/mgar/gar/v2/bin/pcopy 2011-04-18 15:16:52 UTC (rev 14323)
@@ -0,0 +1,163 @@
+#!/opt/csw/bin/perl
+
+use strict;
+use warnings;
+use DirHandle;
+# use Cwd 'abs_path';
+use File::Copy;
+use File::Find;
+use File::Path qw(make_path);
+use Pod::Usage;
+use Getopt::Long;
+
+use Data::Dumper;
+
+# pcopy [-s <regex> ]* [--paxargs <arg>]* <src> <target>
+# Regex: -s 's,(/opt/csw/lib)/(.*\.so),\1/bdb33/\2,'
+# Objectives:
+# - Copy directory trees verbatim
+# - exclude entries
+# - rename / relocate entries on the fly
+# - allow multiple renames (not just the first one as in "pax")
+# - ignore existing umask and force 0755 / 0644
+# - if the target exists verify for identity or use "diff -D" if specified
+
+my $man = 0;
+my $help = 0;
+my $verbose = 0;
+my $matchonly = 0; # Copy only files that match at least one regex
+my @subst;
+
+GetOptions(
+ 's=s' => \@subst,
+ 'm|matchonly' => \$matchonly,
+ 'v' => \$verbose,
+ 'help|?' => \$help,
+ man => \$man)
+ or pod2usage(2);
+pod2usage(1) if $help;
+pod2usage(-exitstatus => 0, -verbose => 2) if $man;
+
+# Use newstyle regexps
+s,\\(\d),\$$1,g foreach(@subst);
+
+# print Dumper( @subst );
+
+pod2usage(1) if( @ARGV != 2 );
+
+my ($fromdir, $todir) = @ARGV;
+
+if( ! -d $fromdir ) {
+ print STDERR "Source directory not found\n";
+ exit( 1 );
+}
+
+if( ! -d $todir ) {
+ make_path( $todir, { verbose => 1, mode => 0775 } );
+}
+
+my %hardlinks;
+sub docopy {
+ my $srcdir = $File::Find::dir;
+ my $name = $_;
+ my $whole = $fromdir . '/' . $File::Find::name;
+
+ # print "D: $srcdir N: $name W: $whole\n";
+
+ # Apply substitutions from left to right
+ # multiple regexp applied in order, empty target -> exclude
+
+ my $target = $File::Find::name;
+ my @matches = ($target);
+ my $didmatch = 0;
+ foreach my $s (@subst) {
+ my $t = $target;
+ $s =~ s/p$//;
+ $s =~ s/\\\(/(/;
+ $s =~ s/\\\)/)/;
+ # print "Regex: $s\n";
+ eval( '$didmatch = 1 if( $target =~ s' . $s . ')');
+ if( $t ne $target ) {
+ push @matches, $target;
+ #$didmatch = 1;
+ }
+ }
+
+ if( !$didmatch && $matchonly ) {
+ return;
+ }
+
+ print join( " >> ", @matches ), "\n" if( $matches[-1] ne '' );
+
+ if( $target eq '' ) {
+ return;
+ }
+
+ my @path = split(/\//, $target);
+ my $targetdir = $todir . '/' . join( '/', @path[0..$#path-1] );
+
+ # Source was a directory, make target hierarchy
+ if( -e $targetdir && ! -d _ ) {
+ print "ERROR: The directory $File::Find::name is already present as file in $targetdir\n";
+ } elsif( ! -d $targetdir ) {
+ make_path( $targetdir, {error => \my $err} );
+ if (@$err) {
+ for my $diag (@$err) {
+ my ($target, $message) = %$diag;
+ if ($target eq '') {
+ print "general error: $message\n";
+ } else {
+ print "problem unlinking $target: $message\n";
+ }
+ }
+ }
+ }
+ if( -d $whole ) {
+ make_path( $todir . '/' . $target );
+ return;
+ }
+
+ # Copy with preserving hardlinks
+ if( -l $whole ) {
+ my $link = readlink( $whole );
+ my $linktarget = $todir . '/' . $target;
+ if( -l $linktarget ) {
+ my $oldlink = readlink( $linktarget );
+ if( $link ne $oldlink ) {
+ print "Could not link to $linktarget as there is already one pointing to $oldlink instead of the new $link\n";
+ }
+ } elsif( -e $linktarget ) {
+ print "Could not link to $linktarget as there is some file already there\n";
+ } else {
+ symlink( $link, $todir . '/' . $target ) or print "Could not link to $todir/$target\n";
+ }
+ } else {
+ my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
+ = stat($whole);
+ if( exists $hardlinks{$ino} ) {
+ link( $hardlinks{$ino}, $todir . '/' . $target ) or
+ print STDERR "Could not hardlink to ${target}\n";
+ } else {
+ copy( $whole, $todir . '/' . $target ) or print "Copy failed\n";
+ chmod( $mode, $todir . '/' . $target );
+ $hardlinks{$ino} = $todir . '/' . $target;
+ }
+ }
+}
+
+# Make output unbuffered
+local( $| ) = 1;
+
+chdir( $fromdir ) or die "Cannot change to directory '$fromdir'\n";
+find({ wanted => \&docopy, no_chdir => 1 }, '.' );
+
+=pod
+
+=head1 SYNOPSIS
+
+ pcopy [-s <regex>]* <from> <to>
+ -m Copy only matched files
+
+=cut
+
+
Property changes on: csw/mgar/gar/v2/bin/pcopy
___________________________________________________________________
Added: svn:executable
+ *
Modified: csw/mgar/gar/v2/gar.mk
===================================================================
--- csw/mgar/gar/v2/gar.mk 2011-04-18 14:50:40 UTC (rev 14322)
+++ csw/mgar/gar/v2/gar.mk 2011-04-18 15:16:52 UTC (rev 14323)
@@ -849,26 +849,27 @@
# This merges the
merge-modulated: install-modulated pre-merge-modulated pre-merge-$(MODULATION) $(MERGE_TARGETS) post-merge-$(MODULATION) post-merge-modulated
+ $(warning M: $(MERGE_DIRS))
@$(MAKECOOKIE)
# Copy the whole tree verbatim
merge-copy-all: $(PKGROOT) $(INSTALLISADIR)
- $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pax -r -w -v $(_PAX_ARGS) \
+ $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pcopy $(_PAX_ARGS) \
$(foreach DIR,$(MERGE_DIRS),-s ",^\(\.$(DIR)/\),.$(call mergebase,$(DIR))/,p") \
. $(PKGROOT))
@$(MAKECOOKIE)
# Copy only the merge directories
merge-copy-only: $(PKGROOT)
- $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pax -r -w -v $(_PAX_ARGS) \
- $(foreach DIR,$(MERGE_DIRS),-s ",^\(\.$(DIR)/\),.$(call mergebase,$(DIR))/,p") -s ",.*,," \
+ $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pcopy $(_PAX_ARGS) \
+ $(foreach DIR,$(MERGE_DIRS),-s ",^\(\.$(DIR)/\),.$(call mergebase,$(DIR))/,p") -m \
. $(PKGROOT) \
)
@$(MAKECOOKIE)
# Copy the whole tree and relocate the directories in $(MERGE_DIRS)
merge-copy-relocate: $(PKGROOT) $(INSTALLISADIR)
- $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pax -r -w -v $(_PAX_ARGS) \
+ $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pcopy $(_PAX_ARGS) \
$(foreach DIR,$(MERGE_DIRS),-s ",^\(\.$(DIR)/\),.$(call mergebase,$(DIR))/$(ISA)/,p") \
. $(PKGROOT) \
)
@@ -876,15 +877,15 @@
# Copy only the relocated directories
merge-copy-relocated-only: $(PKGROOT) $(INSTALLISADIR)
- $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pax -r -w -v $(_PAX_ARGS) \
- $(foreach DIR,$(MERGE_DIRS),-s ",^\(\.$(DIR)/\),.$(call mergebase,$(DIR))/$(ISA)/,p") -s ",.*,," \
+ $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pcopy $(_PAX_ARGS) \
+ $(foreach DIR,$(MERGE_DIRS),-s ",^\(\.$(DIR)/\),.$(call mergebase,$(DIR))/$(ISA)/,p") -m \
. $(PKGROOT) \
)
@$(MAKECOOKIE)
# Copy
merge-copy-config-only:
- $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pax -r -w -v $(_PAX_ARGS) \
+ $(_DBG_MERGE)(cd $(INSTALLISADIR)$(if $(ALLOW_RELOCATE),$(RELOCATE_PREFIX)); umask 022 && pcopy $(_PAX_ARGS) \
-s ",^\(\.$(bindir)/.*-config\)\$$,\1,p" \
-s ",.*,," \
. $(PKGROOT) \
@@ -895,12 +896,13 @@
remerge: reset-merge merge
reset-merge: reset-package $(addprefix reset-merge-,$(MODULATIONS)) reset-merge-license reset-merge-classutils reset-merge-checkpkgoverrides reset-merge-alternatives reset-merge-distfile-README.CSW reset-merge-distfile-changelog.CSW reset-merge-obsolete reset-merge-ap2mod reset-merge-php5ext reset-merge-src
- @rm -f $(COOKIEDIR)/pre-merge $(foreach M,$(MODULATIONS),$(COOKIEDIR)/merge-$M) $(COOKIEDIR)/merge $(COOKIEDIR)/post-merge
- @rm -rf $(PKGROOT)
+ rm -f $(COOKIEDIR)/pre-merge $(foreach M,$(MODULATIONS),$(COOKIEDIR)/merge-$M) $(COOKIEDIR)/merge $(COOKIEDIR)/post-merge
+ rm -rf $(PKGROOT)
reset-merge-modulated:
@$(call _pmod,Reset merge state)
- @rm -f $(COOKIEDIR)/merge-*
+ echo rm -f $(COOKIEDIR)/merge-*
+ rm -f $(COOKIEDIR)/merge-*
# The clean rule. It must be run if you want to re-download a
# file after a successful checksum (or just remove the checksum
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list