File: fgdlaction.cc

package info (click to toggle)
ftpgrab 0.1.5-6
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 444 kB
  • sloc: cpp: 2,906; makefile: 103
file content (91 lines) | stat: -rw-r--r-- 2,009 bytes parent folder | download | duplicates (8)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// fgdlaction.cc

#include "fgdlaction.h"

// Downloading involves interfacing with remote connection
#ifndef _FGCONI_H
#include "fgconi.h"
#endif

#ifndef _FGFSHELP_H
#include "fgfshelp.h"
#endif

#ifndef _FGSTRING_H
#include "fgstring.h"
#endif

#ifndef _FGEXC_H
#include "fgexc.h"
#endif

#ifndef _FGLOGGER_H
#include "fglogger.h"
#endif

FGDownloadAction::FGDownloadAction(const FGString& fname,
                                   FGConnectionInterface* pConnIf,
                                   const FGString& localDir,
                                   int size)
: mpConnIf(pConnIf), mFileName(fname), mLocalDir(localDir),
  mDestFD(-1), mFileSize(size)
{
}

FGDownloadAction::~FGDownloadAction()
{
}

void
FGDownloadAction::VirtualDo(void) const
{
  FGString msg;
  msg = "Starting download of file `";
  msg += mFileName;
  msg += '\'';
  FGLogger::GetLogger().LogMsg(msg, FGLogger::kFGLLVerbose);

  // Interface already has directory state ready for direct grab
  // Also, we're connected at this point
  int dataFD = mpConnIf->GetFile(mFileName);

  // Create the destination file for writing
  FGString destName(mLocalDir);
  destName += '/';
  destName += mFileName;

  try {
    int destFD = FGFileSystemHelper::CreateLocalFile(destName);
    FGFileSystemHelper::TransferRemoteToLocal(dataFD, destFD, mFileSize);
  }
  catch (FGException& e) {
    mpConnIf->PostFileTransfer();
    throw e;
  }

  // Success - cool better log message
  msg = "Successful transfer of file `";
  msg += mFileName;
  msg += '\'';
  FGLogger::GetLogger().LogMsg(msg, FGLogger::kFGLLInfo);

  mpConnIf->PostFileTransfer();
}

void
FGDownloadAction::Abort(void) const
{
  // Something has gone wrong during the download
  // Delete the file we started to download
  // Ignore errors in case we didn't get as far as creating the file
  FGString delFile(mLocalDir);
  delFile += '/';
  delFile += mFileName;

  try {
    FGFileSystemHelper::DeleteFile(delFile);
  }
  catch (FGException&) {
    // Do nothing
  }
}