releasing/cbrtools/perl/RemoteSite/NetDrive.pm
author lorewang
Mon, 22 Nov 2010 10:56:31 +0800
changeset 700 c22eff170fac
parent 602 3145852acc89
permissions -rw-r--r--
update from trunk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
# RemoteSite::NetDrive.pm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
package RemoteSite::NetDrive;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
use File::Copy;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
use RemoteSite;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
use vars qw(@ISA);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
@ISA=("RemoteSite");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
# Initialization 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
sub Initialize {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
  $self->SUPER::Initialize(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
  #connect to network drive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
  $self->Connect();	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
# Public (from RemoteSite)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
sub SendFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
  my $localFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
  my $remoteFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
  unless (defined $localFile and defined $remoteFile) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
    $self->HandleError("Incorrect args passed to ".ref($self)."::SendFile");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
  $remoteFile = Utils::ConcatenateDirNames($self->Host(), $remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
  $remoteFile =~ s{\\}{\/}g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
  if ($self->{verbose}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
    print "Copying ".basename($localFile)." to network drive ".$self->Host()."...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
  elsif (Utils::FileSize($localFile)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
    print "Copying ".basename($localFile)."...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
  unless (-e $localFile) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
    $self->HandleError("Local file $localFile does not exist");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
  $self->Connect();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
  my $remoteDir = dirname($remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
  unless (-e $remoteDir) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
    eval {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
      Utils::MakeDir($remoteDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
    };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
    if ($@) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
      $self->HandleError("Cannot make directory $remoteDir on network drive ".$self->Host());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
    if ($self->{verbose}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
      print "Created directory $remoteDir on network drive\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
  } 	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
  #use a temporary file during uploads
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
  my $tmpFile = $remoteDir.'/TMP_'.basename($remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
  unless (copy($localFile, $tmpFile)){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
    my $flag = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
    my $errormessage = $!;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
    if(-e $tmpFile) { 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
      unlink $tmpFile or $flag=1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
    if($errormessage =~ /No such file or directory/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
      $errormessage = "Unknown Error - Check disk space or missing file/directory";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
    if($flag) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
      $self->HandleError("Unable to cleanup $tmpFile, after the copy of $localFile failed : $errormessage");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
    $self->HandleError("Unable to copy $localFile to $tmpFile : $errormessage");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
  unless (move($tmpFile, $remoteFile)){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
    unlink $tmpFile;    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
    $self->HandleError("Unable to move $tmpFile to $remoteFile : $!");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
  if ($self->{verbose} > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
    print "Copy successful. Stored as $remoteFile on network drive.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
  }  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
sub GetFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
  my $remoteFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
  my $localFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
  unless (defined $localFile and defined $remoteFile) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
    $self->HandleError("Incorrect args passed to ".ref($self)."::GetFile");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
  my $host = $self->Host();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
  $host =~ s{\\}{\/}g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
  $remoteFile =~ s{\\}{\/}g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
  if ($self->{verbose}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
    print "Copying ".basename($remoteFile)." from network drive $host...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
    print "Copying ".basename($remoteFile)."...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
  $self->Connect();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
  if ($self->{verbose}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
    print "Checking whether \"$remoteFile\" exists...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
  unless ($self->FileExists($remoteFile)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
    $self->HandleError("Remote file $remoteFile does not exist on $host");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
  #check local dir exists and create it if it doesn't
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
  my $localDir = dirname($localFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
  unless (-e $localDir) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
    Utils::MakeDir($localDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
    if ($self->{verbose}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
      print "Created directory $localDir on local drive\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
  unless (copy($host.$remoteFile, $localFile)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
    unlink $localFile;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
    $self->HandleError("Transfer of $remoteFile from $host to local drive failed");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
  if ($self->{verbose} > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
    print "Copy successful. Stored as $localFile on local drive.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
sub FileExists {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
  my $remoteFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
  unless (defined $remoteFile) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
    return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
  $self->Connect();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
  $remoteFile = Utils::ConcatenateDirNames($self->Host(), $remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
  $remoteFile =~ s{\\}{\/}g; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
  return (-e $remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
sub DirExists {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
  my $remoteDir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
  return $self->FileExists($remoteDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
sub DirList {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
  my $remoteDir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
  my $host = $self->Host();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
  $host =~ s{\\}{\/}g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
  $remoteDir =~ s{\\}{\/}g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
  opendir(DIR, Utils::ConcatenateDirNames($host, $remoteDir)) or $self->HandleError("Cannot open $remoteDir on network drive ".$self->Host());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
  my @dir = map {"$remoteDir/$_"} grep {$_ ne '.' and $_ ne '..'} readdir DIR;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
  closedir(DIR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
  return \@dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
sub MakeDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
  my $remoteDir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
  $remoteDir = $self->Host().$remoteDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
  $remoteDir =~ s{\\}{\/}g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
  eval {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
    Utils::MakeDir($remoteDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
  };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
  if ($@) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
    $self->HandleError("Cannot make directory $remoteDir on network drive ".$self->Host());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
sub FileSize {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
  my $remoteFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
  $remoteFile = Utils::ConcatenateDirNames($self->Host(), $remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
  $remoteFile =~ s{\\}{\/}g; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
  return Utils::FileSize($remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
sub DeleteFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
  my $remoteFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
  $remoteFile = Utils::ConcatenateDirNames($self->Host(), $remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
  $remoteFile =~ s{\\}{\/}g; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
  rmdir $remoteFile or unlink $remoteFile or $self->HandleError("Cannot delete $remoteFile on network dirve ($!)");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
sub MoveFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
  my $oldFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
  my $newFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
  $oldFile = Utils::ConcatenateDirNames($self->Host(), $oldFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
  $oldFile =~ s{\\}{\/}g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
  $newFile = Utils::ConcatenateDirNames($self->Host(), $newFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
  $newFile =~ s{\\}{\/}g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
  move($oldFile, $newFile) or $self->HandleError("Cannot move $oldFile to $newFile on network drive");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
sub FileModifiedTime {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
  my $remoteFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
  $remoteFile = Utils::ConcatenateDirNames($self->Host(), $remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
  $remoteFile =~ s{\\}{\/}g; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
  return Utils::FileModifiedTime($remoteFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
# Private
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
sub Connect {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
  unless ($self->Host()) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
    $self->HandleError("Network drive host name not defined");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
  my $hostName = $self->Host();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
  unless (-e $hostName) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
    $self->HandleError("Cannot connect to network drive $hostName");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
RemoteSite::NetDrive.pm - Access a remote network drive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
 use RemoteSite::NetDrive;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
 $drive = RemoteSite::NetDrive->New(host => '\\server\share',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
			            verbose => 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
 if ($drive->FileExists('/somedir/someremotefile')) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
   do something...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
 $drive->SendFile('somelocalfile', 'someremotefile');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
 $drive->GetFile('someremotefile', 'somelocalfile');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
C<RemoteSite::NetDrive> is inherited from the abstract base class C<RemoteSite>, implementing the abstract methods required for transfer of files to and from a remote site when the remote site is a network drive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
=head1 INTERFACE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
=head2 New
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
Passed an argument list in the form of hash key value pairs. The supported arguments are...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
  host      => $host_address_string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
  verbose   => $verbosity_integer
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
Returns a reference to a C<RemoteSite::NetDrive> object
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
=head2 Host
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
Returns the current value of the C<host> attribute which contains the UNC path of the network drive. If passed an argument sets the attribute to this new value.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
=head2 SendFile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
Passed a local and a remote file name. Uploads the local file to the network drive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
=head2 GetFile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
Passed a remote and local file name. Downloads the remote file from the network drive and stores it on the local drive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
=head2 FileExists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
Passed a filename (with full path) on the network drive. Returns a non zero value if the file exists.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
None
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
=cut