Rex-Endpoint-HTTP

 view release on metacpan or  search on metacpan

lib/Rex/Endpoint/HTTP/Interface/Fs/Base.pm  view on Meta::CPAN

   my ($self, $path) = @_;

   if(-r $path) {
      return 1;
   }

   return 0;
}

sub is_writable {
   my ($self, $path) = @_;

   if(-w $path) {
      return 1;
   }

   return 0;
}

sub readlink {
   my ($self, $path) = @_;

   my $link = CORE::readlink($path) or die($!);

   return $link;
}

sub rename {
   my ($self, $old, $new) = @_;

   CORE::rename($old, $new) or die($!);

   return 1;
}

sub glob {
   my ($self, $glob) = @_;

   my @ret = CORE::glob($glob);

   return @ret;
}

sub upload {
   my ($self, $path, $upload) = @_;

   open(my $fh, ">", $path) or die($!);
   print $fh $upload->slurp;
   close($fh);

   return 1;
}

sub download {
   my ($self, $path) = @_;

   if(! -f $path) {
      die("File not found.");
   }

   my $content = eval { local(@ARGV, $/) = ($path); <>; };

   return $content;
}

sub ln {
   my ($self, $from, $to) = @_;

   if(-f $to) {
      CORE::unlink($to) or die($!);
   }

   CORE::symlink($from, $to) or die($!);

   return 1;
}

sub rmdir {
   my ($self, $path) = @_;

   system("rm -rf " . $path);

   if($? == 0) {
      return 1;
   }

   die("Error deleting directory.");
}

sub chown {
   my ($self, $user, $file, $options) = @_;

   my $recursive = "";
   if(exists $options->{"recursive"} && $options->{"recursive"} == 1) {
      $recursive = " -R ";
   }

   system("chown $recursive $user $file");

   if($? == 0) {
      return 1;
   }

   die("Error changing ownership of file");
}

sub chgrp {
   my ($self, $group, $file, $options) = @_;

   my $recursive = "";
   if(exists $options->{"recursive"} && $options->{"recursive"} == 1) {
      $recursive = " -R ";
   }

   system("chgrp $recursive $group $file");

   if($? == 0) {
      return 1;
   }

   die("Error chaning group ownership of file");



( run in 0.556 second using v1.01-cache-2.11-cpan-ceb78f64989 )