package DX::Lib::FS::Action::RewriteFile;
use DX::Lib::FS::Fact::FileContent;
-use File::stat;
-use File::Copy;
-use Fcntl qw(O_CREAT O_WRONLY);
+use DX::Lib::FS::Guts;
use Moo;
with 'DX::Role::Action';
sub _do_run {
my ($self) = @_;
- my $stat = stat($self->path) or die "Couldn't stat ${\$self->path}: $!";
- my $perms = $stat->mode & 07777;
- my $new = $self->path.'.new';
- unlink($new);
- sysopen my $fh, $new, O_CREAT | O_WRONLY, $perms
- or die "Couldn't open ${new}: $!";
- print $fh $self->final_content
- or die "Couldn't write data to ${new}: $!";
- close $fh;
- move($new, $self->path) or die "Couldn't install ${new}: $!";
- return +(file_content => $self->from);
+ DX::Lib::FS::Guts->rewrite_file($self->path, $self->final_content);
+ return +(file_content => $self->path);
}
1;