| 1 | package VFSsimple::Drv::Rsync; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use base qw(VFSsimple::Base); | ||
| 6 | use URI (); | ||
| 7 | use File::Temp qw(tempfile); | ||
| 8 | |||
| 9 | our $VERSION = '0.03'; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | VFSsimple::Drv::Rsync - A VFSsimple implementation over rsync protocol | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | This module provide access method for VFSsimple module to access to file | ||
| 18 | located on rsync server. | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | |||
| 23 | sub drv_new { | ||
| 24 | my ($self) = @_; | ||
| 25 | foreach (split(':', $ENV{PATH})) { | ||
| 26 | -x "$_/rsync" and return $self; | ||
| 27 | } | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | sub drv_get { | ||
| 33 | my ($self, $src) = @_; | ||
| 34 | my (undef, $dest) = tempfile(UNLINK => 0); | ||
| 35 | $self->drv_copy($src, $dest); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub drv_copy { | ||
| 39 | my ($self, $src, $dest) = @_; | ||
| 40 | system('rsync', '-q', $self->{root} . '/' . $src, $dest); | ||
| 41 | my $res = $? >> 8; | ||
| 42 | if ($res) { return } | ||
| 43 | return $dest; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub drv_exists { | ||
| 47 | my ($self, $file) = @_; | ||
| 48 | system('rsync', '-q', "$self->{root}/$file"); | ||
| 49 | my $res = $? >> 8; | ||
| 50 | return ($res eq 0); | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; | ||
| 54 | |||
| 55 | __END__ |