diff options
| author | fukachan <fukachan> | 2006-10-22 14:35:00 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2006-10-22 14:35:00 +0000 |
| commit | 024d86a5e4a32ff2a10b5cbc879cbafc2b0d089c (patch) | |
| tree | f3f7740771c8bba6e37cf5bee2d11dfc60f17d79 /fml/lib/FML | |
| parent | 76dacf84693521e20d86e2ff34193ed5da561248 (diff) | |
| download | fml8-024d86a5e4a32ff2a10b5cbc879cbafc2b0d089c.tar.gz fml8-024d86a5e4a32ff2a10b5cbc879cbafc2b0d089c.tar.bz2 fml8-024d86a5e4a32ff2a10b5cbc879cbafc2b0d089c.zip | |
fix comments.
move definitions to near the codes.
use more proper variable names.
Diffstat (limited to 'fml/lib/FML')
| -rw-r--r-- | fml/lib/FML/Command/DirUtils.pm | 40 | ||||
| -rw-r--r-- | fml/lib/FML/Command/FileUtils.pm | 28 |
2 files changed, 45 insertions, 23 deletions
diff --git a/fml/lib/FML/Command/DirUtils.pm b/fml/lib/FML/Command/DirUtils.pm index 46e9e15a..64557eac 100644 --- a/fml/lib/FML/Command/DirUtils.pm +++ b/fml/lib/FML/Command/DirUtils.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: DirUtils.pm,v 1.22 2006/03/05 08:08:36 fukachan Exp $ +# $FML: DirUtils.pm,v 1.23 2006/03/05 09:50:42 fukachan Exp $ # package FML::Command::DirUtils; @@ -19,8 +19,14 @@ FML::Command::DirUtils - utilities for directory handlings. =head1 SYNOPSIS + use FML::Command::DirUtils; + my $obj = new FML::Command::DirUtils; + $obj->dir($curproc, $command_context, $du_args); + =head1 DESCRIPTION +This class provides utilities for directory handlings. + =head1 METHODS =head2 new() @@ -46,6 +52,14 @@ sub new return bless $me, $type; } + +=head2 dir($curproc, $command_context, $du_args) + +show the result by executing "ls". + +=cut + + # # XXX-TODO: if we can find CPAN module for dir listing, use it. # @@ -58,27 +72,24 @@ sub new sub dir { my ($self, $curproc, $command_context, $du_args) = @_; - my $config = $curproc->config(); - my $path_ls = $config->{ path_ls }; - my $argv = $du_args->{ argv }; - my $opt_ls = ''; - my $rm_args = {}; + my $config = $curproc->config(); # inherit reply_message information. + my $rm_args = {}; my $recipient = $command_context->{ recipient } || ''; if ($recipient) { $rm_args->{ recipient } = $recipient;} # option: permit "ls [-A-Za-z]" syntax + my $safe_opt_ls = ''; if (defined($du_args->{ opt_ls })) { - use FML::Restriction::Base; - my $safe = new FML::Restriction::Base; my $opt = $du_args->{ opt_ls }; + my $safe = $self->{ _safe }; if ($safe->regexp_match('command_line_options', $opt)) { - $opt_ls = $opt; + $safe_opt_ls = $opt; } else { $curproc->logwarn("deny ls options '$opt'"); - $opt_ls = ''; + $safe_opt_ls = ''; } } @@ -90,15 +101,18 @@ sub dir chdir $ml_home_dir || croak("cannot chdir \$ml_home_dir"); # build safe arguments - my $y = ''; + my $safe_args = ''; + my $argv = $du_args->{ argv }; for my $x (@$argv) { if ($safe->regexp_match('directory', $x) || $x =~ /^\s*$/) { - $y .= " $x"; + $safe_args .= " $x"; } } + # execute ls command. + my $path_ls = $config->{ path_ls }; if (-x $path_ls) { - my $eval = "$path_ls $opt_ls $y"; + my $eval = "$path_ls $safe_opt_ls $safe_args"; $curproc->log("dir: run \"$eval\""); use FileHandle; diff --git a/fml/lib/FML/Command/FileUtils.pm b/fml/lib/FML/Command/FileUtils.pm index 38c7a94e..7c8614b5 100644 --- a/fml/lib/FML/Command/FileUtils.pm +++ b/fml/lib/FML/Command/FileUtils.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: FileUtils.pm,v 1.19 2006/03/05 08:08:36 fukachan Exp $ +# $FML: FileUtils.pm,v 1.20 2006/03/05 09:50:42 fukachan Exp $ # package FML::Command::FileUtils; @@ -19,8 +19,17 @@ FML::Command::FileUtils - utilities to handle files. =head1 SYNOPSIS +use FML::Command::FileUtils; +my $obj = new FML::Command::FileUtils; +$obj->remove($curproc, $command_context, $du_args); + =head1 DESCRIPTION +This class provides file operation functions. + +remove(), same as delete() method can be used to remove files under +$ml_home_dir. + =head1 METHODS =head2 new() @@ -54,20 +63,20 @@ same as remove() below. =head2 remove($curproc, $command_context, $du_aregs) remove files specified in $du_args->{ options } -if the file exsits and the file name matches safe file regexp defined -in FML::Restriction class. +if the file exsits and the file name matches the safe file regexp +defined in FML::Restriction class. =cut # Descriptions: remove files. -# Arguments: OBJ($self) VARARGS(@p) +# Arguments: OBJ($self) VARARGS(@var_args) # Side Effects: remove files # Return Value: same as remove() sub delete { - my ($self, @p) = @_; - $self->remove(@p); + my ($self, @var_args) = @_; + $self->remove(@var_args); } @@ -80,16 +89,15 @@ sub remove { my ($self, $curproc, $command_context, $du_args) = @_; my $config = $curproc->config(); - my $argv = $du_args->{ options }; my $is_error = 0; - # regexp allowed here for file - my $safe = $self->{ _safe }; - # chdir $ml_home_dir firstly. return ASAP if failed. my $ml_home_dir = $config->{ ml_home_dir }; chdir $ml_home_dir || croak("cannot chdir \$ml_home_dir"); + # validate file and remove it if ok. + my $argv = $du_args->{ options }; + my $safe = $self->{ _safe }; # regexp allowed here for file for my $file (@$argv) { # If $file is a safe pattern, o.k. Try to remove it! if ($safe->regexp_match('file', $file)) { |
