/[pxelator]/lib/PXElator/file.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/file.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 290 by dpavlin, Wed Aug 26 08:43:40 2009 UTC revision 438 by dpavlin, Sun Sep 20 16:11:16 2009 UTC
# Line 6  use Carp qw/carp confess/; Line 6  use Carp qw/carp confess/;
6  use File::Path qw//;  use File::Path qw//;
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8    
9  my $debug = 1;  my $debug = 0;
10    
11  sub mkpath {  sub mkpath {
12          my $file = shift;          my $file = shift;
13          my $dir = $1 if $file =~ s{^.+/[^/]+}{};          my $dir = $1 if $file =~ s{(^.+)/[^/]+}{$1};
14          File::Path::mkpath $dir unless -e $dir;          if ( $dir && ! -d $dir ) {
15                    carp "# mkdir $dir";
16                    File::Path::mkpath $dir;
17            }
18  }  }
19    
20  sub append {  sub append {
# Line 36  sub append { Line 39  sub append {
39  #               $content =~ s{[\n\r]*$}{\n}s;  #               $content =~ s{[\n\r]*$}{\n}s;
40    
41                  if ( $on_disk =~ s{([\s+]exit[\s\d]*)$}{\n$content\n$1}s ) {                  if ( $on_disk =~ s{([\s+]exit[\s\d]*)$}{\n$content\n$1}s ) {
42  #                       warn "# insert $file\n$on_disk";                          warn "# insert $file\n$on_disk" if $debug;
43                          write_file $file, $on_disk;                          write_file $file, $on_disk;
44                  } else {                  } else {
45  #                       warn "# append $file\n$content\n";                          warn "# append $file\n$content\n" if $debug;
46                          open($fh, '>>', $file);                          open($fh, '>>', $file);
47                          print $fh $content;                          print $fh $content;
48                          close($fh);                          close($fh);
49                  }                  }
50    
51                  carp "## append to $file";                  carp "## append to $file" if $debug;
52                  return -s $file;                  return -s $file;
53            } else {
54                    warn "## $file not modified" if $debug;
55          }          }
56  }  }
57    
# Line 71  sub replace { Line 76  sub replace {
76    
77  sub copy_once {  sub copy_once {
78          my ( $from, $to ) = @_;          my ( $from, $to ) = @_;
79          $to ||= $from;          die "no destination" unless $to;
80          return if -e $to;          return if -e $to;
81          mkpath $to;          mkpath $to;
82          write_file $to, read_file $from;          my $perm = (stat $from)[2];
83  #       warn "# copy_once $to ", -s $to, " bytes";          carp "# copy_once $from => $to $perm";
84            write_file $to, read_file($from);
85            chmod $perm, $to;
86  }  }
87    
88  1;  1;

Legend:
Removed from v.290  
changed lines
  Added in v.438

  ViewVC Help
Powered by ViewVC 1.1.26