|
Packit |
90a5c9 |
#!/usr/bin/perl -w
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
# contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
# this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
# (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
# the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
# See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
# limitations under the License.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
use strict;
|
|
Packit |
90a5c9 |
use File::Basename;
|
|
Packit |
90a5c9 |
use File::Copy;
|
|
Packit |
90a5c9 |
use File::Find;
|
|
Packit |
90a5c9 |
use File::Path qw(mkpath);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
require 5.010;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
my $srcdir;
|
|
Packit |
90a5c9 |
my $destdir;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sub process_file {
|
|
Packit |
90a5c9 |
return if $_ =~ /^\./;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
my $rel_to_srcdir = substr($File::Find::name, length($srcdir));
|
|
Packit |
90a5c9 |
my $destfile = "$destdir$rel_to_srcdir";
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (-d $File::Find::name) {
|
|
Packit |
90a5c9 |
# If the directory is empty, it won't get created.
|
|
Packit |
90a5c9 |
# Otherwise it will get created when copying a file.
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
if (-f $destfile) {
|
|
Packit |
90a5c9 |
# Preserve it.
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
# Create it.
|
|
Packit |
90a5c9 |
my $dir = dirname($destfile);
|
|
Packit |
90a5c9 |
if (! -e $dir) {
|
|
Packit |
90a5c9 |
mkpath($dir) or die "Failed to create directory $dir: $!";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
copy($File::Find::name, $destfile) or die "Copy $File::Find::name->$destfile failed: $!";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
$srcdir = shift;
|
|
Packit |
90a5c9 |
$destdir = shift;
|
|
Packit |
90a5c9 |
if (scalar(@ARGV) > 0) {
|
|
Packit |
90a5c9 |
my $mode = shift;
|
|
Packit |
90a5c9 |
if ($mode eq "ifdestmissing") {
|
|
Packit |
90a5c9 |
# Normally the check for possible overwrite is performed on a
|
|
Packit |
90a5c9 |
# file-by-file basis. If "ifdestmissing" is specified and the
|
|
Packit |
90a5c9 |
# destination directory exists, bail out.
|
|
Packit |
90a5c9 |
if (-d $destdir) {
|
|
Packit |
90a5c9 |
print "[PRESERVING EXISTING SUBDIR $destdir]\n";
|
|
Packit |
90a5c9 |
exit(0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
die "bad mode $mode";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
find(\&process_file, ($srcdir));
|