| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # $Id: Tgz.pm,v 1.6 2005/02/18 11:58:26 eserte Exp $ | ||||||||||||||||||||||||||||
| 5 | # Author: Slaven Rezic | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # Copyright (C) 2004 Slaven Rezic. | ||||||||||||||||||||||||||||
| 8 | # This is free software; you can redistribute it and/or modify it under the | ||||||||||||||||||||||||||||
| 9 | # terms of the GNU General Public License, see the file COPYING. | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | # Mail: slaven@rezic.de | ||||||||||||||||||||||||||||
| 13 | # WWW: http://we-framework.sourceforge.net | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | package WE_Frontend::Publish::Tgz; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use WE_Frontend::Publish; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use WE::Util::Functions qw(_save_pwd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use WE_Frontend::Info 1.33; # staging->message | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # for compatibility: | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub WE_Frontend::Main::publish_tgz { | ||||||||||||||||||||||||||
|
Subroutine
publish_tgz: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 30 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||
| 31 | 0 | publish_tgz($self, %args); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Return created $archivefile | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub publish_tgz { | ||||||||||||||||||||||||||
|
Subroutine
publish_tgz: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | require Archive::Tar; | |||||||||||||||||||||||||||
| 39 | 0 | require File::Find; | |||||||||||||||||||||||||||
| 40 | 0 | require File::Spec; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | my $v = $args{-v}; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | my $archivefileformat = $self->Config->staging->archivefile; | |||||||||||||||||||||||||||
| 45 | 0 | my $pubhtmldir = $self->Config->paths->pubhtmldir; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (!defined $archivefileformat) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | die "The WEsiteinfo->staging->archivefile config member is not defined"; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (!defined $pubhtmldir || $pubhtmldir eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $pubhtmldir or $pubhtmldir eq ""
MC/DC0%0/2
not defined $pubhtmldir or $pubhtmldir eq ""
not defined $pubhtmldir
$pubhtmldir eq ""
Truth table0%0/3
not(A) or B
A= not defined $pubhtmldirB= $pubhtmldir eq ""
| |||||||||||||||||||||||||||||
| 51 | 0 | die "The publish html directory is missing (config member WEsiteinfo->paths->pubhtmldir)"; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my @l = localtime; | |||||||||||||||||||||||||||
| 55 | 0 | my $date = sprintf "%04d%02d%02d-%02d%02d%02d", $l[5]+1900, $l[4]+1, @l[3,2,1,0]; | |||||||||||||||||||||||||||
| 56 | 0 | (my $archivefile = $archivefileformat) =~ s/\@DATE\@/$date/g; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $tar = Archive::Tar->new(); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | print "Add to archive...\n"; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | _save_pwd { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 62 | 0 | my @files; | |||||||||||||||||||||||||||
| 63 | my %absfiles; | ||||||||||||||||||||||||||||
| 64 | 0 | my @symlinks; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | chdir $pubhtmldir or die "Can't chdir to $pubhtmldir: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | File::Find::find | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | (sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return if -d; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | # exclude: | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return if $File::Find::name =~ m{^\./we/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | return if $File::Find::name =~ m{/(CVS|RCS|\.svn)/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return if m{^( \.cvsignore | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | | \.keep_me # yes? no? XXX | ||||||||||||||||||||||||||||
| 74 | | .*~ | ||||||||||||||||||||||||||||
| 75 | | \.\#.*\.\d+ # a CVS related file | ||||||||||||||||||||||||||||
| 76 | | \.DS_Store | ||||||||||||||||||||||||||||
| 77 | )$}x; | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (-l) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | my $readlink = readlink($_); | |||||||||||||||||||||||||||
| 80 | 0 | push @symlinks, [$File::Find::name, $readlink, File::Spec->rel2abs($readlink)]; | |||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||
| 82 | 0 | print $File::Find::name, "\n"; | |||||||||||||||||||||||||||
| 83 | 0 | push @files, $File::Find::name; | |||||||||||||||||||||||||||
| 84 | 0 | $absfiles{ File::Spec->rel2abs($_) } = $File::Find::name; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | }, "."); | |||||||||||||||||||||||||||
| 87 | #XXX require Data::Dumper; print STDERR "Line " . __LINE__ . ", File: " . __FILE__ . "\n" . Data::Dumper->new([[sort keys %absfiles], \@symlinks],[])->Indent(1)->Useqq(1)->Dump; # XXX | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | for my $symlinkdef (@symlinks) { | |||||||||||||||||||||||||||
| 90 | 0 | my($file, $relfile, $absfile) = @$symlinkdef; | |||||||||||||||||||||||||||
| 91 | # XXX Archive::Tar 1.10 bug: | ||||||||||||||||||||||||||||
| 92 | # XXX only one symlink of multiple to the same file can be | ||||||||||||||||||||||||||||
| 93 | # stored, so use no symlinks at all... | ||||||||||||||||||||||||||||
| 94 | 0 | if (0 && exists $absfiles{$absfile}) { | |||||||||||||||||||||||||||
| 95 | # XXX make sure it's a relative link! | ||||||||||||||||||||||||||||
| 96 | # push @files, File::Spec->abs2rel($file, | ||||||||||||||||||||||||||||
| 97 | print "Symlink $file -> $relfile\n"; | ||||||||||||||||||||||||||||
| 98 | push @files, $file; | ||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if (!open(FH, $absfile)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | print "Skipping $absfile, can't open $!\n"; | |||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||
| 103 | 0 | local $/ = undef; | |||||||||||||||||||||||||||
| 104 | 0 | my $buf = <FH>; | |||||||||||||||||||||||||||
| 105 | 0 | print "Symlink not available on target system, store data for $file\n"; | |||||||||||||||||||||||||||
| 106 | 0 | $tar->add_data($file, $buf); | |||||||||||||||||||||||||||
| 107 | 0 | close FH; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | $tar->add_files(@files); | |||||||||||||||||||||||||||
| 112 | 0 | }; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | $tar->write($archivefile, 1, "htdocs"); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | my $message = $self->Config->staging->message; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (!$message) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 118 | 0 | print "\nArchive file $archivefile written...\n"; | |||||||||||||||||||||||||||
| 119 | } elsif (ref $message eq 'CODE') { | ||||||||||||||||||||||||||||
| 120 | 0 | print $message->(archivefile => $archivefile); | |||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||
| 122 | 0 | print $message; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | return $archivefile; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # Apache.pm-friendly system() | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub _system { | ||||||||||||||||||||||||||
|
Subroutine
_system: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 130 | 0 | my $cmd = shift; | |||||||||||||||||||||||||||
| 131 | 0 | open(SYS, "$cmd|"); | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | while(<SYS>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | print $_; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | 0 | close SYS; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 1 | 1; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | __END__ | ||||||||||||||||||||||||||||