Hi,
tttee has the capability of copying files. That's nice, but with large
files (think MP3, AVI, FLV, ...) it's rather disk consuming to
maintain multiple, identical copies of the big files.
So I've added a 'link' capability. It is similar to 'copy', but links
instead. Should the link fail, copy is used as fallback.
Patch against a ttree 2.86 attached.
-- Johan
*** /usr/bin/ttree 2007-02-21 19:30:36.000000000 +0100
--- ttree 2007-07-27 15:23:17.000000000 +0200
***************
*** 72,77 ****
--- 72,78 ----
my $libdir = $config->lib;
my $ignore = $config->ignore;
my $copy = $config->copy;
+ my $link = $config->link;
my $accept = $config->accept;
my $absolute = $config->absolute;
my $relative = $config->relative;
***************
*** 176,181 ****
--- 177,183 ----
"Include Path: [ @$libdir ]\n",
" Ignore: [ @$ignore ]\n",
" Copy: [ @$copy ]\n",
+ " Link: [ @$link ]\n",
" Accept: [ @$accept ]\n",
" Suffix: [ $sfx ]\n");
print(" Module: $ttmodule ", $ttmodule->module_version
(), "\n")
***************
*** 303,308 ****
--- 305,311 ----
my ($old_suffix, $new_suffix);
my $is_dep = 0;
my $copy_file = 0;
+ my $link_file = 0;
$absfile ||= $file;
$filename = basename($file);
***************
*** 321,335 ****
# print "proc $file => $dest\n";
! # check against copy list
! foreach my $copy_pattern (@$copy) {
! if ($filename =~ /$copy_pattern/) {
! $copy_file = 1;
! $check = $copy_pattern;
last;
}
}
# stat the source file unconditionally, so we can preserve
# mode and ownership
( undef, undef, $mode, undef, $uid, $gid, undef,
--- 324,349 ----
# print "proc $file => $dest\n";
! # check against link list
! foreach my $link_pattern (@$link) {
! if ($filename =~ /$link_pattern/) {
! $link_file = $copy_file = 1;
! $check = $link_pattern;
last;
}
}
+ unless ( $copy_file ) {
+ # check against copy list
+ foreach my $copy_pattern (@$copy) {
+ if ($filename =~ /$copy_pattern/) {
+ $copy_file = 1;
+ $check = $copy_pattern;
+ last;
+ }
+ }
+ }
+
# stat the source file unconditionally, so we can preserve
# mode and ownership
( undef, undef, $mode, undef, $uid, $gid, undef,
***************
*** 355,360 ****
--- 369,391 ----
}
# check against copy list
+ if ( $link_file ) {
+ unless ($dryrun) {
+ if ( link($absfile, $dest) == 1 ) {
+ $copy_file = 0;
+ }
+ else {
+ warn "Could not link ($absfile to $dest) : $!\n";
+ }
+ }
+
+ unless ( $copy_file ) {
+ printf " > %-32s (linked, matches /$check/)\n", $file
+ if $verbose;
+ return;
+ }
+ }
+
if ($copy_file) {
unless ($dryrun) {
copy($absfile, $dest) or die "Could not copy
($absfile to $dest) : $!\n";
***************
*** 526,531 ****
--- 557,563 ----
'suffix=s%',
'ignore=s@',
'copy=s@',
+ 'link=s@',
'accept=s@',
'depend=s%',
'depend_debug|depdbg',
***************
*** 620,625 ****
--- 652,660 ----
copy = \\.png\$
copy = \\.gif\$
+ # ditto for things that should be linked rather than copied /
processed.
+ # link = \\.flv\$
+
# by default, everything not ignored or copied is accepted; add
'accept'
# lines if you want to filter further. e.g.
#
***************
*** 694,699 ****
--- 729,735 ----
File search specifications (all may appear multiple times):
--ignore=REGEX Ignore files matching REGEX
--copy=REGEX Copy files matching REGEX
+ --link=REGEX Link files matching REGEX
--accept=REGEX Process only files matching REGEX
File Dependencies Options:
***************
*** 790,800 ****
/home/abw/.ttreerc created. Please edit accordingly and re-
run ttree
The purpose of this file is to set any I<global> configuration
options
! that you want applied I<every> time F<ttree> is run. For
example, you
! can use the C<ignore> and C<copy> option to provide regular
expressions
! that specify which files should be ignored and which should be
copied
! rather than being processed as templates. You may also want to set
! flags like C<verbose> and C<recurse> according to your preference.
A minimal F<.ttreerc>:
--- 826,837 ----
/home/abw/.ttreerc created. Please edit accordingly and re-
run ttree
The purpose of this file is to set any I<global> configuration
options
! that you want applied I<every> time F<ttree> is run. For example,
you
! can use the C<ignore> and C<copy> / C<link> options to provide
regular
! expressions that specify which files should be ignored and which
! should be copied or linked rather than being processed as templates.
! You may also want to set flags like C<verbose> and C<recurse>
! according to your preference.
A minimal F<.ttreerc>:
***************
*** 927,940 ****
=head2 File Options
! The C<ignore>, C<copy> and C<accept> options are used to specify
Perl
! regexen to filter file names. Files that match any of the C<ignore>
! options will not be processed. Remaining files that match any of
the
! C<copy> regexen will be copied to the destination directory.
Remaining
! files that then match any of the C<accept> criteria are then
processed
! via the Template Toolkit. If no C<accept> parameter is specified
then
! all files will be accepted for processing if not already copied or
! ignored.
# ignore these files
ignore = \b(CVS|RCS)\b
--- 964,977 ----
=head2 File Options
! The C<ignore>, C<copy>, C<link> and C<accept> options are used to
! specify Perl regexen to filter file names. Files that match any
of the
! C<ignore> options will not be processed. Remaining files that match
! any of the C<copy> or C<link> regexen will be copied or linked to
the
! destination directory. Remaining files that then match any of the
! C<accept> criteria are then processed via the Template Toolkit.
If no
! C<accept> parameter is specified then all files will be accepted for
! processing if not already copied or ignored.
# ignore these files
ignore = \b(CVS|RCS)\b