rewrite file correctly chaining from create file
[scpubgit/DKit.git] / lib / DX / Lib / FS / Action / CreateFile.pm
index 426b241..c05b3ef 100644 (file)
@@ -1,5 +1,6 @@
 package DX::Lib::FS::Action::CreateFile;
 
+use aliased 'DX::Lib::FS::Fact::FileContent';
 use aliased 'DX::Lib::FS::Fact::PathStatus';
 use aliased 'DX::Lib::FS::Fact::PathStatusInfo';
 use Fcntl qw(O_CREAT O_WRONLY);
@@ -11,6 +12,8 @@ has path => (is => 'ro', required => 1);
 
 has mode => (is => 'ro', predicate => 1);
 
+has data => (is => 'ro', default => sub { '' });
+
 sub expected_effect {
   my ($self) = @_;
   return +(path_status => PathStatus->new(
@@ -19,6 +22,9 @@ sub expected_effect {
       is_file => 1,
       mode => ($self->has_mode ? $self->mode : '')
     )
+  ), file_content => FileContent->new(
+    path => $self->path,
+    data => $self->data,
   ));
 }
 
@@ -35,6 +41,7 @@ sub _do_run {
     sysopen($fh, $self->path, O_CREAT | O_WRONLY)
       or die "Couldn't create ${\$self->path}: $!";
   }
+  print $fh $self->data if length($self->data);
   +(path_status => PathStatus->new(path => $self->path));
 }