File: fgpickallsync.cc

package info (click to toggle)
ftpgrab 0.1.2r-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 376 kB
  • ctags: 335
  • sloc: cpp: 2,790; makefile: 26
file content (67 lines) | stat: -rw-r--r-- 1,810 bytes parent folder | download | duplicates (4)
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
// fgpickallsync.cc

#include "fgpickallsync.h"

// Dir listings
#ifndef _FGDLIST_H
#include "fgdlist.h"
#endif

// Action lists
#ifndef _FGALIST_H
#include "fgalist.h"
#endif

// The download file action
#ifndef _FGDLACTION_H
#include "fgdlaction.h"
#endif

// The local erase file action
#ifndef _FGDELACTION_H
#include "fgdelaction.h"
#endif

FGPickAllSync::FGPickAllSync(FGConnectionInterface* pConnIf)
: FGFilePickerInterface(pConnIf)
{
}

FGActionList
FGPickAllSync::DecideActions(const FGDirListing& localDir,
                             const FGDirListing& remoteDir)
{
  // The picker for the "normal" wildcard operation (non recursive),
  // leaves all local files intact
  // Very simple rule: grab any file in the remoteDir that is
  // not in the localDir
  FGActionList ret;

  // Get list of files in local but not remote
  FGDirListing staleFiles = FGDirListing::GetRHSOnlyFiles(remoteDir, localDir);

  // For each stale file, make an "erase" action
  vector<FGFileInfo>::const_iterator iFiles;
  for (iFiles = staleFiles.begin(); iFiles != staleFiles.end(); iFiles++) {
    FGActionInterface* pNewAction;

    pNewAction = new FGDeleteAction(iFiles->GetFileName(),
                                    localDir.GetDirName());
    ret.push_back(pNewAction);
  }

  // Get list of files in remote but not local
  FGDirListing newFiles = FGDirListing::GetRHSOnlyFiles(localDir, remoteDir);

  // Make a "download" action for all the above files
  for (iFiles = newFiles.begin(); iFiles != newFiles.end(); iFiles++) {
    FGActionInterface* pNewAction;

    pNewAction = new FGDownloadAction(iFiles->GetFileName(), mpConnIf,
                                      localDir.GetDirName(),
                                      iFiles->GetSize());
    ret.push_back(pNewAction);
  }

  return ret;
}