Ignore:
Timestamp:
11/14/09 04:07:33 (2 years ago)
Author:
Sewi
Message:

Some small fixes and minor changes to Padre::File::FTP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/File/FTP.pm

    r9177 r9215  
    1616    my $url = shift; 
    1717 
    18     my $config = Padre->ide->config; 
    19  
    2018    # Create myself 
    2119    my $self = bless { filename => $url }, $class; 
     20 
     21    # Using the config is optional, tests and other usages should run without 
     22    my $config = eval { return Padre->ide->config; }; 
     23    if (defined($config)) { 
     24        $self->{_timeout} = $config->file_ftp_timeout; 
     25        $self->{_passive} = $config->file_ftp_passive; 
     26    } else { 
     27        # Use defaults if we have no config 
     28        $self->{_timeout} = 60; 
     29        $self->{_passive} = 1; 
     30    } 
    2231 
    2332    # Don't add a new overall-dependency to Padre: 
     
    7281        Host    => $self->{_host}, 
    7382        Port    => $self->{_port}, 
    74         Timeout => $config->file_ftp_timeout, 
    75         Passive => $config->file_ftp_passive, 
     83        Timeout => $self->{_timeout}, 
     84        Passive => $self->{_passive}, 
    7685 
    7786        #       Debug => 3, # Enable for FTP-debugging to STDERR 
     
    135144    my $self = shift; 
    136145    return if !defined( $self->{_ftp} ); 
    137     return $self->size ? 1 : 0; 
     146 
     147    # Cache basename value 
     148    my $basename = $self->basename; 
     149 
     150    for ($self->{_ftp}->ls($self->{_file})) { 
     151        return 1 if $_ eq $self->{_file}; 
     152        return 1 if $_ eq $basename; 
     153    } 
     154 
     155    # Fallback if ->ls didn't help. A file heaving a size should exist. 
     156    return 1 if $self->size; 
     157 
     158    return 0; 
    138159} 
    139160 
     
    147168} 
    148169 
     170# This method should return the dirname to be used inside Padre, not the one 
     171# used on the FTP-server. 
    149172sub dirname { 
    150173    my $self = shift; 
    151174 
    152     my $dir = $self->{_file}; 
     175    my $dir = $self->{filename}; 
    153176    $dir =~ s/\/[^\/]*$//; 
    154177 
     
    194217} 
    195218 
     219############################################################################### 
     220### Internal FTP helper functions 
     221 
     222sub _ftp_dirname { 
     223    my $self = shift; 
     224 
     225    my $dir = $self->{_file}; 
     226    $dir =~ s/\/[^\/]*$//; 
     227 
     228    return $dir; 
     229} 
     230 
     231 
    1962321; 
    197233 
Note: See TracChangeset for help on using the changeset viewer.