source: box/trunk/bin/bbackupd/BackupClientDeleteList.cpp @ 2983

Revision 2983, 6.1 KB checked in by chris, 9 months ago (diff)

Combine client and server protocols to make way for an offline/local protocol.

Rename ProtocolObject? to Message.

  • Property svn:eol-style set to native
Line 
1// --------------------------------------------------------------------------
2//
3// File
4//              Name:    BackupClientDeleteList.cpp
5//              Purpose: List of pending deletes for backup
6//              Created: 10/11/03
7//
8// --------------------------------------------------------------------------
9
10#include "Box.h"
11
12#include <algorithm>
13
14#include "BackupClientDeleteList.h"
15#include "BackupClientContext.h"
16#include "autogen_BackupProtocol.h"
17
18#include "MemLeakFindOn.h"
19
20
21// --------------------------------------------------------------------------
22//
23// Function
24//              Name:    BackupClientDeleteList::BackupClientDeleteList()
25//              Purpose: Constructor
26//              Created: 10/11/03
27//
28// --------------------------------------------------------------------------
29BackupClientDeleteList::BackupClientDeleteList()
30{
31}
32
33// --------------------------------------------------------------------------
34//
35// Function
36//              Name:    BackupClientDeleteList::~BackupClientDeleteList()
37//              Purpose: Destructor
38//              Created: 10/11/03
39//
40// --------------------------------------------------------------------------
41BackupClientDeleteList::~BackupClientDeleteList()
42{
43}
44
45BackupClientDeleteList::FileToDelete::FileToDelete(int64_t DirectoryID,
46        const BackupStoreFilename& rFilename,
47        const std::string& rLocalPath)
48: mDirectoryID(DirectoryID),
49  mFilename(rFilename),
50  mLocalPath(rLocalPath)
51{ }
52
53BackupClientDeleteList::DirToDelete::DirToDelete(int64_t ObjectID,
54        const std::string& rLocalPath)
55: mObjectID(ObjectID),
56  mLocalPath(rLocalPath)
57{ }
58
59// --------------------------------------------------------------------------
60//
61// Function
62//              Name:    BackupClientDeleteList::AddDirectoryDelete(int64_t,
63//                       const BackupStoreFilename&)
64//              Purpose: Add a directory to the list of directories to be deleted.
65//              Created: 10/11/03
66//
67// --------------------------------------------------------------------------
68void BackupClientDeleteList::AddDirectoryDelete(int64_t ObjectID,
69        const std::string& rLocalPath)
70{
71        // Only add the delete to the list if it's not in the "no delete" set
72        if(mDirectoryNoDeleteList.find(ObjectID) ==
73                mDirectoryNoDeleteList.end())
74        {
75                // Not in the list, so should delete it
76                mDirectoryList.push_back(DirToDelete(ObjectID, rLocalPath));
77        }
78}
79
80
81// --------------------------------------------------------------------------
82//
83// Function
84//              Name:    BackupClientDeleteList::AddFileDelete(int64_t,
85//                       const BackupStoreFilename &)
86//              Purpose:
87//              Created: 10/11/03
88//
89// --------------------------------------------------------------------------
90void BackupClientDeleteList::AddFileDelete(int64_t DirectoryID,
91        const BackupStoreFilename &rFilename, const std::string& rLocalPath)
92{
93        // Try to find it in the no delete list
94        std::vector<std::pair<int64_t, BackupStoreFilename> >::iterator
95                delEntry(mFileNoDeleteList.begin());
96        while(delEntry != mFileNoDeleteList.end())
97        {
98                if((delEntry)->first == DirectoryID
99                        && (delEntry)->second == rFilename)
100                {
101                        // Found!
102                        break;
103                }
104                ++delEntry;
105        }
106       
107        // Only add it to the delete list if it wasn't in the no delete list
108        if(delEntry == mFileNoDeleteList.end())
109        {
110                mFileList.push_back(FileToDelete(DirectoryID, rFilename,
111                        rLocalPath));
112        }
113}
114
115
116       
117// --------------------------------------------------------------------------
118//
119// Function
120//              Name:    BackupClientDeleteList::PerformDeletions(BackupClientContext &rContext)
121//              Purpose: Perform all the pending deletes
122//              Created: 10/11/03
123//
124// --------------------------------------------------------------------------
125void BackupClientDeleteList::PerformDeletions(BackupClientContext &rContext)
126{
127        // Anything to do?
128        if(mDirectoryList.empty() && mFileList.empty())
129        {
130                // Nothing!
131                return;
132        }
133       
134        // Get a connection
135        BackupProtocolClient &connection(rContext.GetConnection());
136       
137        // Do the deletes
138        for(std::vector<DirToDelete>::iterator i(mDirectoryList.begin());
139                i != mDirectoryList.end(); ++i)
140        {
141                connection.QueryDeleteDirectory(i->mObjectID);
142                rContext.GetProgressNotifier().NotifyDirectoryDeleted(
143                        i->mObjectID, i->mLocalPath);
144        }
145       
146        // Clear the directory list
147        mDirectoryList.clear();
148       
149        // Delete the files
150        for(std::vector<FileToDelete>::iterator i(mFileList.begin());
151                i != mFileList.end(); ++i)
152        {
153                connection.QueryDeleteFile(i->mDirectoryID, i->mFilename);
154                rContext.GetProgressNotifier().NotifyFileDeleted(
155                        i->mDirectoryID, i->mLocalPath);
156        }
157}
158
159
160// --------------------------------------------------------------------------
161//
162// Function
163//              Name:    BackupClientDeleteList::StopDirectoryDeletion(int64_t)
164//              Purpose: Stop a directory being deleted
165//              Created: 19/11/03
166//
167// --------------------------------------------------------------------------
168void BackupClientDeleteList::StopDirectoryDeletion(int64_t ObjectID)
169{
170        // First of all, is it in the delete vector?
171        std::vector<DirToDelete>::iterator delEntry(mDirectoryList.begin());
172        for(; delEntry != mDirectoryList.end(); delEntry++)
173        {
174                if(delEntry->mObjectID == ObjectID)
175                {
176                        // Found!
177                        break;
178                }
179        }
180        if(delEntry != mDirectoryList.end())
181        {
182                // erase this entry
183                mDirectoryList.erase(delEntry);
184        }
185        else
186        {
187                // Haven't been asked to delete it yet, put it in the
188                // no delete list
189                mDirectoryNoDeleteList.insert(ObjectID);
190        }
191}
192
193
194// --------------------------------------------------------------------------
195//
196// Function
197//              Name:    BackupClientDeleteList::StopFileDeletion(int64_t, const BackupStoreFilename &)
198//              Purpose: Stop a file from being deleted
199//              Created: 19/11/03
200//
201// --------------------------------------------------------------------------
202void BackupClientDeleteList::StopFileDeletion(int64_t DirectoryID,
203        const BackupStoreFilename &rFilename)
204{
205        // Find this in the delete list
206        std::vector<FileToDelete>::iterator delEntry(mFileList.begin());
207        while(delEntry != mFileList.end())
208        {
209                if(delEntry->mDirectoryID == DirectoryID
210                        && delEntry->mFilename == rFilename)
211                {
212                        // Found!
213                        break;
214                }
215                ++delEntry;
216        }
217       
218        if(delEntry != mFileList.end())
219        {
220                // erase this entry
221                mFileList.erase(delEntry);
222        }
223        else
224        {
225                // Haven't been asked to delete it yet, put it in the no delete list
226                mFileNoDeleteList.push_back(std::pair<int64_t, BackupStoreFilename>(DirectoryID, rFilename));
227        }
228}
229
Note: See TracBrowser for help on using the repository browser.