| 1 | # SMB-Perl library, Copyright (C) 2014 Mikhael Goikhman, migo@cpan.org | ||
| 2 | # | ||
| 3 | # This program is free software: you can redistribute it and/or modify | ||
| 4 | # it under the terms of the GNU General Public License as published by | ||
| 5 | # the Free Software Foundation, either version 3 of the License, or | ||
| 6 | # (at your option) any later version. | ||
| 7 | # | ||
| 8 | # This program is distributed in the hope that it will be useful, | ||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | # GNU General Public License for more details. | ||
| 12 | # | ||
| 13 | # You should have received a copy of the GNU General Public License | ||
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | |||
| 16 | package SMB::Tree; | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | use warnings; | ||
| 20 | |||
| 21 | use parent 'SMB'; | ||
| 22 | |||
| 23 | use SMB::File; | ||
| 24 | |||
| 25 | sub new ($$$%) { | ||
| 26 | my $class = shift; | ||
| 27 | my $share = shift || die "No share in constructor"; | ||
| 28 | my $id = shift || die "No tree id in constructor"; | ||
| 29 | my %options = @_; | ||
| 30 | |||
| 31 | $options{addr} //= undef; # remote | ||
| 32 | $options{root} //= undef; # local | ||
| 33 | |||
| 34 | my $self = $class->SUPER::new( | ||
| 35 | %options, | ||
| 36 | share => $share, | ||
| 37 | id => $id, | ||
| 38 | ); | ||
| 39 | |||
| 40 | die "Neither 'root' for local tree nor 'addr' for remote tree in constructor" | ||
| 41 | unless $self->is_local || $self->is_remote; | ||
| 42 | |||
| 43 | return $self; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub is_ipc ($) { | ||
| 47 | my $self = shift; | ||
| 48 | |||
| 49 | return $self->share eq 'IPC$'; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub is_local ($) { | ||
| 53 | my $self = shift; | ||
| 54 | |||
| 55 | return $self->root || $self->is_ipc; | ||
| 56 | } | ||
| 57 | |||
| 58 | sub is_remote ($) { | ||
| 59 | my $self = shift; | ||
| 60 | |||
| 61 | return $self->addr && $self->client; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub perform_remote_command ($$@) { | ||
| 65 | my $self = shift; | ||
| 66 | my $command = shift; | ||
| 67 | |||
| 68 | die unless $self->is_remote; | ||
| 69 | |||
| 70 | $self->client->perform_tree_command($self, $command, @_); | ||
| 71 | } | ||
| 72 | |||
| 73 | sub chdir { shift()->perform_remote_command('chdir', @_); } | ||
| 74 | sub find { shift()->perform_remote_command('find', @_); } | ||
| 75 | sub dnload { shift()->perform_remote_command('dnload', @_); } | ||
| 76 | sub upload { shift()->perform_remote_command('upload', @_); } | ||
| 77 | sub copy { shift()->perform_remote_command('copy', @_); } | ||
| 78 | sub rename { shift()->perform_remote_command('rename', @_); } | ||
| 79 | sub remove { shift()->perform_remote_command('remove', @_); } | ||
| 80 | |||
| 81 | 1; |