Skip to content

Commit

Permalink
コメント行は最後にまとめて出力するように変更。postfix と dovecot が見事に似た感じのものになったのでどうにかしたい
Browse files Browse the repository at this point in the history
  • Loading branch information
vkgtaro committed Dec 23, 2009
1 parent a18dc50 commit e624ae3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lib/Taroweb/Dovecot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ has accounts => (
default => sub { {} }
);

has comments => (
is => 'rw',
isa => 'Str',
);

coerce 'File'
=> from 'Str'
=> via { file($_) };
Expand All @@ -39,12 +44,19 @@ sub read_passwd_file {
my $fh = $self->passwd_file->openr
or die 'can not open '. $self->passwd_file . q{:} . $!;

my $comments = '';
while ( my $line = <$fh> ) {
next if $line =~ /^#/;
if ( $line =~ /^#/ ) {
$comments .= $line;
next;
}

my ($account, $domain, $hashed_password) = $self->parse_line_from_passwd_file($line);
$self->accounts->{$domain}->{$account} = $hashed_password;
}

$self->comments( $comments );

return $self->accounts;
}

Expand Down Expand Up @@ -108,6 +120,7 @@ sub write_passwd_file {

my $contents = $self->as_string;
$fh->print($contents);
$fh->print($self->comments);

flock($fh, LOCK_UN);
return $fh->close;
Expand Down
15 changes: 14 additions & 1 deletion lib/Taroweb/Postfix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ has accounts => (
default => sub { {} }
);

has comments => (
is => 'rw',
isa => 'Str',
);

coerce 'File'
=> from 'Str'
=> via { file($_) };
Expand All @@ -38,12 +43,19 @@ sub read_virtual_file {
my $fh = $self->virtual->openr
or die 'can not open '. $self->virtual;

my $comments = '';
while ( my $line = <$fh> ) {
next if $line =~ /^#/;
if ( $line =~ /^#/ ) {
$comments .= $line;
next;
}

my ($account, $domain, $dir) = $self->parse_line_from_virtual_file($line);
$self->accounts->{$domain}->{$account} = $dir;
}

$self->comments( $comments );

return $self->accounts;
}

Expand Down Expand Up @@ -110,6 +122,7 @@ sub write_virtual_file {

my $contents = $self->as_string;
$fh->print($contents);
$fh->print($self->comments);

flock($fh, LOCK_UN);
return $fh->close;
Expand Down

0 comments on commit e624ae3

Please sign in to comment.