File: get.cc

package info (click to toggle)
stealth 1.45-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 716 kB
  • ctags: 175
  • sloc: cpp: 1,612; makefile: 88; sh: 70
file content (53 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "scanner.ih"

// Command forms:
//      GET                   remote-file local-file
//      GET NOTEST            remote-file local-file

void Scanner::get(string const &cmd)
{
    Util::debug() << "Scanner::get(): " << cmd << endl;

    removeFirstWord("GET");                         // strip off `GET'

    d_testExitValue = !removeFirstWord("NOTEST");   // [NOTEST] ...

    // at this point we have the remote-file and the local-file in the
    // command. d_firstword[1] contains the remote filename,
    //          d_firstword[3] contains the rest    


    string source = s_firstWord[1];                 // get the (remote) source

    if (!source.length())
        d_reporter.exit() << "GET command requires source and destination" <<
                            endl;
            

    s_firstWord.match(s_firstWord[3]);              // strip off source
    string destination = s_firstWord[1];            // get the local dest.

    if (!destination.length())
        d_reporter.exit() << 
            "At `GET " << source << " <destination>': destination missing" <<
            endl;
            
    if (Util::isDirectory(destination))             // is the dest. a dir. ?
        destination += "/" + Util::fileName(source); 


    Util::debug() << "Scanner::get(): scp <client>:" << source << " " << 
                                                     destination << endl;

    if (Arg::instance().option('n'))     // no run if -n
        return;

    nextCommand(d_sshFork,                  // start the next command
        d_sorter["DD"] + " if=" + source);

    read(d_sshFork, destination);       // read its output, tests exit value

    Util::debug() << "Scanner::get(): " << cmd << " DONE" << endl;
}