From: Matt S Trout Date: Fri, 14 Feb 2014 09:01:41 +0000 (+0000) Subject: SetPathMode action X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae75ed8bebfa414fe476001bafdbea09714ac584;p=scpubgit%2FDKit.git SetPathMode action --- diff --git a/lib/DX/Lib/FS.pm b/lib/DX/Lib/FS.pm index 220daec..2fb204c 100644 --- a/lib/DX/Lib/FS.pm +++ b/lib/DX/Lib/FS.pm @@ -3,6 +3,7 @@ package DX::Lib::FS; use DX::Lib::FS::Observation::PathStatus; use DX::Lib::FS::Action::CreateDirectory; use DX::Lib::FS::Action::CreateFile; +use DX::Lib::FS::Action::SetPathMode; use File::Spec; use DX::SetOver; use Moo; @@ -88,6 +89,14 @@ our @RULES = ( [ react => [ qw(PS M) ], sub { $_[0]->but(mode => $_[1]); } ] ] ], + [ mode => [ qw(PS M) ], + [ exists_path => qw(PS) ], + [ not => [ info_prop => 'PS', \'mode', 'M' ] ], + [ act => [ qw(PS M) ], sub { + DX::Lib::FS::Action::SetPathMode->new( + path_status => $_[0], mode => $_[1] + ) + } ] ], ); sub load_into { diff --git a/lib/DX/Lib/FS/Action/SetPathMode.pm b/lib/DX/Lib/FS/Action/SetPathMode.pm new file mode 100644 index 0000000..f7cba83 --- /dev/null +++ b/lib/DX/Lib/FS/Action/SetPathMode.pm @@ -0,0 +1,23 @@ +package DX::Lib::FS::Action::SetPathMode; + +use Moo; + +has path_status => (is => 'ro', required => 1); +has mode => (is => 'ro', required => 1); + +with 'DX::Role::Action'; + +sub expected_effect { + my ($self) = @_; + my $ps = $self->path_status; + +(path_status => $ps->but(info => $ps->info->but(mode => $self->mode))); +} + +sub _do_run { + my ($self) = @_; + chmod oct($self->mode), $self->path_status->path + or die "Failed to chmod ${\$self->path_status->path} to ${\$self->mode}: $!"; + +(path_status => $self->path_status); +} + +1; diff --git a/lib/DX/Lib/FS/Fact/PathStatusInfo.pm b/lib/DX/Lib/FS/Fact/PathStatusInfo.pm index a7201ff..d1894a5 100644 --- a/lib/DX/Lib/FS/Fact/PathStatusInfo.pm +++ b/lib/DX/Lib/FS/Fact/PathStatusInfo.pm @@ -6,4 +6,6 @@ has is_directory => (is => 'ro', default => 0); has is_file => (is => 'ro', default => 0); has mode => (is => 'ro', required => 1); +with 'DX::Role::Fact'; + 1;