From 8f09673745acf3c55ad511142dd6b7a85deeebbd Mon Sep 17 00:00:00 2001 From: Bernd Blessmann Date: Wed, 16 Nov 2011 11:22:01 +0100 Subject: [PATCH] =?utf8?q?Bei=20Vorlagens=C3=A4tzen=20werden=20auch=20Unte?= =?utf8?q?rverzeichnisse=20und=20Symlinks=20kopiert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- bin/mozilla/admin.pl | 51 +++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index c776961ab..9fe0bab68 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -37,6 +37,9 @@ use Encode; use English qw(-no_match_vars); use Fcntl; use File::Copy; +use File::Find; +use File::Spec; +use Cwd; use IO::File; use POSIX qw(strftime); use Sys::Hostname; @@ -539,26 +542,40 @@ sub save_user { umask(007); # copy templates to the directory - my $templatedir = "$::lx_office_conf{paths}->{templates}/mastertemplates/$form->{mastertemplates}"; - opendir TEMPLATEDIR, $templatedir or $form->error($templatedir . " : $ERRNO"); - my @templates = grep /.*?\.(html|tex|sty|odt|xml|txb)$/, - readdir TEMPLATEDIR; - closedir TEMPLATEDIR; - - foreach my $file (@templates) { - open(TEMP, "<", $templatedir . "/$file") - or $form->error($templatedir . "/$file : $ERRNO"); + my $oldcurrdir = getcwd(); + if (!chdir("$::lx_office_conf{paths}->{templates}/mastertemplates/$form->{mastertemplates}")) { + $form->error("$ERRNO: chdir $::lx_office_conf{paths}->{templates}/mastertemplates/$form->{mastertemplates}"); + } - open(NEW, ">", "$form->{templates}/$file") - or $form->error("$form->{templates}/$file : $ERRNO"); + my $newdir = File::Spec->catdir($oldcurrdir, $form->{templates}); + + find( + sub + { + next if ($_ eq "."); + + if (-d $_) { + if (!mkdir (File::Spec->catdir($newdir, $File::Find::name))) { + chdir($oldcurrdir); + $form->error("$ERRNO: mkdir $File::Find::name"); + } + } elsif (-l $_) { + if (!symlink (readlink($_), + File::Spec->catfile($newdir, $File::Find::name))) { + chdir($oldcurrdir); + $form->error("$ERRNO: symlink $File::Find::name"); + } + } elsif (-f $_ && $_ =~ m/.*?\.(html|tex|sty|odt|xml|txb|eps|pdf|png|jpg)$/) { + if (!copy($_, File::Spec->catfile($newdir, $File::Find::name))) { + chdir($oldcurrdir); + $form->error("$ERRNO: cp $File::Find::name"); + } + } + }, "./"); + + chdir($oldcurrdir); - while (my $line = ) { - print NEW $line; - } - close(TEMP); - close(NEW); - } } else { $form->error("$ERRNO: $form->{templates}"); } -- 2.20.1