1 | /* $Id: VFSExplorerImpl.cpp 32718 2010-09-23 12:57:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * IVFSExplorer COM class implementations.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include <iprt/dir.h>
|
---|
20 | #include <iprt/path.h>
|
---|
21 | #include <iprt/file.h>
|
---|
22 | #include <iprt/s3.h>
|
---|
23 | #include <iprt/cpp/utils.h>
|
---|
24 |
|
---|
25 | #include <VBox/com/array.h>
|
---|
26 |
|
---|
27 | #include <VBox/param.h>
|
---|
28 | #include <VBox/version.h>
|
---|
29 |
|
---|
30 | #include "VFSExplorerImpl.h"
|
---|
31 | #include "VirtualBoxImpl.h"
|
---|
32 | #include "ProgressImpl.h"
|
---|
33 |
|
---|
34 | #include "AutoCaller.h"
|
---|
35 | #include "Logging.h"
|
---|
36 |
|
---|
37 | #include <memory>
|
---|
38 |
|
---|
39 | ////////////////////////////////////////////////////////////////////////////////
|
---|
40 | //
|
---|
41 | // VFSExplorer definitions
|
---|
42 | //
|
---|
43 | ////////////////////////////////////////////////////////////////////////////////
|
---|
44 |
|
---|
45 | /* opaque private instance data of VFSExplorer class */
|
---|
46 | struct VFSExplorer::Data
|
---|
47 | {
|
---|
48 | struct DirEntry
|
---|
49 | {
|
---|
50 | DirEntry(Utf8Str aName, VFSFileType_T aType)
|
---|
51 | : name(aName)
|
---|
52 | , type(aType) {}
|
---|
53 |
|
---|
54 | Utf8Str name;
|
---|
55 | VFSFileType_T type;
|
---|
56 | };
|
---|
57 |
|
---|
58 | VFSType_T storageType;
|
---|
59 | Utf8Str strUsername;
|
---|
60 | Utf8Str strPassword;
|
---|
61 | Utf8Str strHostname;
|
---|
62 | Utf8Str strPath;
|
---|
63 | Utf8Str strBucket;
|
---|
64 |
|
---|
65 | std::list<DirEntry> entryList;
|
---|
66 | };
|
---|
67 |
|
---|
68 | VFSExplorer::VFSExplorer()
|
---|
69 | : mVirtualBox(NULL)
|
---|
70 | {
|
---|
71 | }
|
---|
72 |
|
---|
73 | VFSExplorer::~VFSExplorer()
|
---|
74 | {
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * VFSExplorer COM initializer.
|
---|
80 | * @param
|
---|
81 | * @return
|
---|
82 | */
|
---|
83 | HRESULT VFSExplorer::init(VFSType_T aType, Utf8Str aFilePath, Utf8Str aHostname, Utf8Str aUsername, Utf8Str aPassword, VirtualBox *aVirtualBox)
|
---|
84 | {
|
---|
85 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
86 | AutoInitSpan autoInitSpan(this);
|
---|
87 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
88 |
|
---|
89 | /* Weak reference to a VirtualBox object */
|
---|
90 | unconst(mVirtualBox) = aVirtualBox;
|
---|
91 |
|
---|
92 | /* initialize data */
|
---|
93 | m = new Data;
|
---|
94 |
|
---|
95 | m->storageType = aType;
|
---|
96 | m->strPath = aFilePath;
|
---|
97 | m->strHostname = aHostname;
|
---|
98 | m->strUsername = aUsername;
|
---|
99 | m->strPassword = aPassword;
|
---|
100 |
|
---|
101 | if (m->storageType == VFSType_S3)
|
---|
102 | {
|
---|
103 | size_t bpos = aFilePath.find("/", 1);
|
---|
104 | if (bpos != Utf8Str::npos)
|
---|
105 | {
|
---|
106 | m->strBucket = aFilePath.substr(1, bpos - 1); /* The bucket without any slashes */
|
---|
107 | aFilePath = aFilePath.substr(bpos); /* The rest of the file path */
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | /* Confirm a successful initialization */
|
---|
112 | autoInitSpan.setSucceeded();
|
---|
113 |
|
---|
114 | return S_OK;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * VFSExplorer COM uninitializer.
|
---|
119 | * @return
|
---|
120 | */
|
---|
121 | void VFSExplorer::uninit()
|
---|
122 | {
|
---|
123 | delete m;
|
---|
124 | m = NULL;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Public method implementation.
|
---|
129 | * @param
|
---|
130 | * @return
|
---|
131 | */
|
---|
132 | STDMETHODIMP VFSExplorer::COMGETTER(Path)(BSTR *aPath)
|
---|
133 | {
|
---|
134 | if (!aPath)
|
---|
135 | return E_POINTER;
|
---|
136 |
|
---|
137 | AutoCaller autoCaller(this);
|
---|
138 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
139 |
|
---|
140 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
141 |
|
---|
142 | Bstr bstrPath(m->strPath);
|
---|
143 | bstrPath.cloneTo(aPath);
|
---|
144 |
|
---|
145 | return S_OK;
|
---|
146 | }
|
---|
147 |
|
---|
148 | STDMETHODIMP VFSExplorer::COMGETTER(Type)(VFSType_T *aType)
|
---|
149 | {
|
---|
150 | if (!aType)
|
---|
151 | return E_POINTER;
|
---|
152 |
|
---|
153 | AutoCaller autoCaller(this);
|
---|
154 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
155 |
|
---|
156 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
157 |
|
---|
158 | *aType = m->storageType;
|
---|
159 |
|
---|
160 | return S_OK;
|
---|
161 | }
|
---|
162 |
|
---|
163 | struct VFSExplorer::TaskVFSExplorer
|
---|
164 | {
|
---|
165 | enum TaskType
|
---|
166 | {
|
---|
167 | Update,
|
---|
168 | Delete
|
---|
169 | };
|
---|
170 |
|
---|
171 | TaskVFSExplorer(TaskType aTaskType, VFSExplorer *aThat, Progress *aProgress)
|
---|
172 | : taskType(aTaskType),
|
---|
173 | pVFSExplorer(aThat),
|
---|
174 | progress(aProgress),
|
---|
175 | rc(S_OK)
|
---|
176 | {}
|
---|
177 | ~TaskVFSExplorer() {}
|
---|
178 |
|
---|
179 | int startThread();
|
---|
180 | static int taskThread(RTTHREAD aThread, void *pvUser);
|
---|
181 | static int uploadProgress(unsigned uPercent, void *pvUser);
|
---|
182 |
|
---|
183 | TaskType taskType;
|
---|
184 | VFSExplorer *pVFSExplorer;
|
---|
185 | ComObjPtr<Progress> progress;
|
---|
186 | HRESULT rc;
|
---|
187 |
|
---|
188 | /* task data */
|
---|
189 | std::list<Utf8Str> filenames;
|
---|
190 | };
|
---|
191 |
|
---|
192 | int VFSExplorer::TaskVFSExplorer::startThread()
|
---|
193 | {
|
---|
194 | int vrc = RTThreadCreate(NULL, VFSExplorer::TaskVFSExplorer::taskThread, this,
|
---|
195 | 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
|
---|
196 | "Explorer::Task");
|
---|
197 |
|
---|
198 | if (RT_FAILURE(vrc))
|
---|
199 | return VFSExplorer::setErrorStatic(E_FAIL, Utf8StrFmt("Could not create taskThreadVFS (%Rrc)\n", vrc));
|
---|
200 |
|
---|
201 | return vrc;
|
---|
202 | }
|
---|
203 |
|
---|
204 | /* static */
|
---|
205 | DECLCALLBACK(int) VFSExplorer::TaskVFSExplorer::taskThread(RTTHREAD /* aThread */, void *pvUser)
|
---|
206 | {
|
---|
207 | std::auto_ptr<TaskVFSExplorer> task(static_cast<TaskVFSExplorer*>(pvUser));
|
---|
208 | AssertReturn(task.get(), VERR_GENERAL_FAILURE);
|
---|
209 |
|
---|
210 | VFSExplorer *pVFSExplorer = task->pVFSExplorer;
|
---|
211 |
|
---|
212 | LogFlowFuncEnter();
|
---|
213 | LogFlowFunc(("VFSExplorer %p\n", pVFSExplorer));
|
---|
214 |
|
---|
215 | HRESULT rc = S_OK;
|
---|
216 |
|
---|
217 | switch(task->taskType)
|
---|
218 | {
|
---|
219 | case TaskVFSExplorer::Update:
|
---|
220 | {
|
---|
221 | if (pVFSExplorer->m->storageType == VFSType_File)
|
---|
222 | rc = pVFSExplorer->updateFS(task.get());
|
---|
223 | else if (pVFSExplorer->m->storageType == VFSType_S3)
|
---|
224 | rc = pVFSExplorer->updateS3(task.get());
|
---|
225 | break;
|
---|
226 | }
|
---|
227 | case TaskVFSExplorer::Delete:
|
---|
228 | {
|
---|
229 | if (pVFSExplorer->m->storageType == VFSType_File)
|
---|
230 | rc = pVFSExplorer->deleteFS(task.get());
|
---|
231 | else if (pVFSExplorer->m->storageType == VFSType_S3)
|
---|
232 | rc = pVFSExplorer->deleteS3(task.get());
|
---|
233 | break;
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
238 | LogFlowFuncLeave();
|
---|
239 |
|
---|
240 | return VINF_SUCCESS;
|
---|
241 | }
|
---|
242 |
|
---|
243 | /* static */
|
---|
244 | int VFSExplorer::TaskVFSExplorer::uploadProgress(unsigned uPercent, void *pvUser)
|
---|
245 | {
|
---|
246 | VFSExplorer::TaskVFSExplorer* pTask = *(VFSExplorer::TaskVFSExplorer**)pvUser;
|
---|
247 |
|
---|
248 | if (pTask &&
|
---|
249 | !pTask->progress.isNull())
|
---|
250 | {
|
---|
251 | BOOL fCanceled;
|
---|
252 | pTask->progress->COMGETTER(Canceled)(&fCanceled);
|
---|
253 | if (fCanceled)
|
---|
254 | return -1;
|
---|
255 | pTask->progress->SetCurrentOperationProgress(uPercent);
|
---|
256 | }
|
---|
257 | return VINF_SUCCESS;
|
---|
258 | }
|
---|
259 |
|
---|
260 | VFSFileType_T VFSExplorer::RTToVFSFileType(int aType) const
|
---|
261 | {
|
---|
262 | VFSFileType_T t;
|
---|
263 | switch(aType)
|
---|
264 | {
|
---|
265 | default:
|
---|
266 | case RTDIRENTRYTYPE_UNKNOWN: t = VFSFileType_Unknown; break;
|
---|
267 | case RTDIRENTRYTYPE_FIFO: t = VFSFileType_Fifo; break;
|
---|
268 | case RTDIRENTRYTYPE_DEV_CHAR: t = VFSFileType_DevChar; break;
|
---|
269 | case RTDIRENTRYTYPE_DIRECTORY: t = VFSFileType_Directory; break;
|
---|
270 | case RTDIRENTRYTYPE_DEV_BLOCK: t = VFSFileType_DevBlock; break;
|
---|
271 | case RTDIRENTRYTYPE_FILE: t = VFSFileType_File; break;
|
---|
272 | case RTDIRENTRYTYPE_SYMLINK: t = VFSFileType_SymLink; break;
|
---|
273 | case RTDIRENTRYTYPE_SOCKET: t = VFSFileType_Socket; break;
|
---|
274 | case RTDIRENTRYTYPE_WHITEOUT: t = VFSFileType_WhiteOut; break;
|
---|
275 | }
|
---|
276 | return t;
|
---|
277 | }
|
---|
278 |
|
---|
279 | HRESULT VFSExplorer::updateFS(TaskVFSExplorer *aTask)
|
---|
280 | {
|
---|
281 | LogFlowFuncEnter();
|
---|
282 |
|
---|
283 | AutoCaller autoCaller(this);
|
---|
284 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
285 |
|
---|
286 | AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
287 |
|
---|
288 | HRESULT rc = S_OK;
|
---|
289 |
|
---|
290 | std::list<VFSExplorer::Data::DirEntry> fileList;
|
---|
291 | char *pszPath = NULL;
|
---|
292 | PRTDIR pDir = NULL;
|
---|
293 | try
|
---|
294 | {
|
---|
295 | pszPath = RTStrDup(m->strPath.c_str());
|
---|
296 | RTPathStripFilename(pszPath);
|
---|
297 | int vrc = RTDirOpen(&pDir, pszPath);
|
---|
298 | if (RT_FAILURE(vrc))
|
---|
299 | throw setError(VBOX_E_FILE_ERROR, tr ("Can't open directory '%s' (%Rrc)"), pszPath, vrc);
|
---|
300 |
|
---|
301 | if (aTask->progress)
|
---|
302 | aTask->progress->SetCurrentOperationProgress(33);
|
---|
303 | RTDIRENTRY entry;
|
---|
304 | while (RT_SUCCESS(vrc))
|
---|
305 | {
|
---|
306 | vrc = RTDirRead(pDir, &entry, NULL);
|
---|
307 | if (RT_SUCCESS(vrc))
|
---|
308 | {
|
---|
309 | Utf8Str name(entry.szName);
|
---|
310 | if (name != "." &&
|
---|
311 | name != "..")
|
---|
312 | fileList.push_back(VFSExplorer::Data::DirEntry(name, RTToVFSFileType(entry.enmType)));
|
---|
313 | }
|
---|
314 | }
|
---|
315 | if (aTask->progress)
|
---|
316 | aTask->progress->SetCurrentOperationProgress(66);
|
---|
317 | }
|
---|
318 | catch(HRESULT aRC)
|
---|
319 | {
|
---|
320 | rc = aRC;
|
---|
321 | }
|
---|
322 |
|
---|
323 | /* Clean up */
|
---|
324 | if (pszPath)
|
---|
325 | RTStrFree(pszPath);
|
---|
326 | if (pDir)
|
---|
327 | RTDirClose(pDir);
|
---|
328 |
|
---|
329 | if (aTask->progress)
|
---|
330 | aTask->progress->SetCurrentOperationProgress(99);
|
---|
331 |
|
---|
332 | /* Assign the result on success (this clears the old list) */
|
---|
333 | if (rc == S_OK)
|
---|
334 | m->entryList.assign(fileList.begin(), fileList.end());
|
---|
335 |
|
---|
336 | aTask->rc = rc;
|
---|
337 |
|
---|
338 | if (!aTask->progress.isNull())
|
---|
339 | aTask->progress->notifyComplete(rc);
|
---|
340 |
|
---|
341 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
342 | LogFlowFuncLeave();
|
---|
343 |
|
---|
344 | return VINF_SUCCESS;
|
---|
345 | }
|
---|
346 |
|
---|
347 | HRESULT VFSExplorer::deleteFS(TaskVFSExplorer *aTask)
|
---|
348 | {
|
---|
349 | LogFlowFuncEnter();
|
---|
350 |
|
---|
351 | AutoCaller autoCaller(this);
|
---|
352 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
353 |
|
---|
354 | AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
355 |
|
---|
356 | HRESULT rc = S_OK;
|
---|
357 |
|
---|
358 | float fPercentStep = 100.0f / aTask->filenames.size();
|
---|
359 | try
|
---|
360 | {
|
---|
361 | char szPath[RTPATH_MAX];
|
---|
362 | std::list<Utf8Str>::const_iterator it;
|
---|
363 | size_t i = 0;
|
---|
364 | for (it = aTask->filenames.begin();
|
---|
365 | it != aTask->filenames.end();
|
---|
366 | ++it, ++i)
|
---|
367 | {
|
---|
368 | memcpy(szPath, m->strPath.c_str(), strlen(m->strPath.c_str()) + 1);
|
---|
369 | RTPathStripFilename(szPath);
|
---|
370 | RTPathAppend(szPath, sizeof(szPath), (*it).c_str());
|
---|
371 | int vrc = RTFileDelete(szPath);
|
---|
372 | if (RT_FAILURE(vrc))
|
---|
373 | throw setError(VBOX_E_FILE_ERROR, tr ("Can't delete file '%s' (%Rrc)"), szPath, vrc);
|
---|
374 | if (aTask->progress)
|
---|
375 | aTask->progress->SetCurrentOperationProgress((ULONG)(fPercentStep * i));
|
---|
376 | }
|
---|
377 | }
|
---|
378 | catch(HRESULT aRC)
|
---|
379 | {
|
---|
380 | rc = aRC;
|
---|
381 | }
|
---|
382 |
|
---|
383 | aTask->rc = rc;
|
---|
384 |
|
---|
385 | if (!aTask->progress.isNull())
|
---|
386 | aTask->progress->notifyComplete(rc);
|
---|
387 |
|
---|
388 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
389 | LogFlowFuncLeave();
|
---|
390 |
|
---|
391 | return VINF_SUCCESS;
|
---|
392 | }
|
---|
393 |
|
---|
394 | HRESULT VFSExplorer::updateS3(TaskVFSExplorer *aTask)
|
---|
395 | {
|
---|
396 | LogFlowFuncEnter();
|
---|
397 |
|
---|
398 | AutoCaller autoCaller(this);
|
---|
399 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
400 |
|
---|
401 | AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
402 |
|
---|
403 | HRESULT rc = S_OK;
|
---|
404 |
|
---|
405 | RTS3 hS3 = NULL;
|
---|
406 | std::list<VFSExplorer::Data::DirEntry> fileList;
|
---|
407 | try
|
---|
408 | {
|
---|
409 | int vrc = RTS3Create(&hS3, m->strUsername.c_str(), m->strPassword.c_str(), m->strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
|
---|
410 | if (RT_FAILURE(vrc))
|
---|
411 | throw setError(E_FAIL, tr ("Can't open S3 storage service (%Rrc)"), vrc);
|
---|
412 |
|
---|
413 | RTS3SetProgressCallback(hS3, VFSExplorer::TaskVFSExplorer::uploadProgress, &aTask);
|
---|
414 | /* Do we need the list of buckets or keys? */
|
---|
415 | if (m->strBucket.isEmpty())
|
---|
416 | {
|
---|
417 | PCRTS3BUCKETENTRY pBuckets = NULL;
|
---|
418 | vrc = RTS3GetBuckets(hS3, &pBuckets);
|
---|
419 | if (RT_FAILURE(vrc))
|
---|
420 | throw setError(E_FAIL, tr ("Can't get buckets (%Rrc)"), vrc);
|
---|
421 |
|
---|
422 | PCRTS3BUCKETENTRY pTmpBuckets = pBuckets;
|
---|
423 | while (pBuckets)
|
---|
424 | {
|
---|
425 | fileList.push_back(VFSExplorer::Data::DirEntry(pBuckets->pszName, VFSFileType_Directory));
|
---|
426 | pBuckets = pBuckets->pNext;
|
---|
427 | }
|
---|
428 | RTS3BucketsDestroy(pTmpBuckets);
|
---|
429 | }
|
---|
430 | else
|
---|
431 | {
|
---|
432 | PCRTS3KEYENTRY pKeys = NULL;
|
---|
433 | vrc = RTS3GetBucketKeys(hS3, m->strBucket.c_str(), &pKeys);
|
---|
434 | if (RT_FAILURE(vrc))
|
---|
435 | throw setError(E_FAIL, tr ("Can't get keys for bucket (%Rrc)"), vrc);
|
---|
436 |
|
---|
437 | PCRTS3KEYENTRY pTmpKeys = pKeys;
|
---|
438 | while (pKeys)
|
---|
439 | {
|
---|
440 | Utf8Str name(pKeys->pszName);
|
---|
441 | fileList.push_back(VFSExplorer::Data::DirEntry(pKeys->pszName, VFSFileType_File));
|
---|
442 | pKeys = pKeys->pNext;
|
---|
443 | }
|
---|
444 | RTS3KeysDestroy(pTmpKeys);
|
---|
445 | }
|
---|
446 | }
|
---|
447 | catch(HRESULT aRC)
|
---|
448 | {
|
---|
449 | rc = aRC;
|
---|
450 | }
|
---|
451 |
|
---|
452 | if (hS3 != NULL)
|
---|
453 | RTS3Destroy(hS3);
|
---|
454 |
|
---|
455 | /* Assign the result on success (this clears the old list) */
|
---|
456 | if (rc == S_OK)
|
---|
457 | m->entryList.assign(fileList.begin(), fileList.end());
|
---|
458 |
|
---|
459 | aTask->rc = rc;
|
---|
460 |
|
---|
461 | if (!aTask->progress.isNull())
|
---|
462 | aTask->progress->notifyComplete(rc);
|
---|
463 |
|
---|
464 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
465 | LogFlowFuncLeave();
|
---|
466 |
|
---|
467 | return VINF_SUCCESS;
|
---|
468 | }
|
---|
469 |
|
---|
470 | HRESULT VFSExplorer::deleteS3(TaskVFSExplorer *aTask)
|
---|
471 | {
|
---|
472 | LogFlowFuncEnter();
|
---|
473 |
|
---|
474 | AutoCaller autoCaller(this);
|
---|
475 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
476 |
|
---|
477 | AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
478 |
|
---|
479 | HRESULT rc = S_OK;
|
---|
480 |
|
---|
481 | RTS3 hS3 = NULL;
|
---|
482 | float fPercentStep = 100.0f / aTask->filenames.size();
|
---|
483 | try
|
---|
484 | {
|
---|
485 | int vrc = RTS3Create(&hS3, m->strUsername.c_str(), m->strPassword.c_str(), m->strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
|
---|
486 | if (RT_FAILURE(vrc))
|
---|
487 | throw setError(E_FAIL, tr ("Can't open S3 storage service (%Rrc)"), vrc);
|
---|
488 |
|
---|
489 | RTS3SetProgressCallback(hS3, VFSExplorer::TaskVFSExplorer::uploadProgress, &aTask);
|
---|
490 |
|
---|
491 | std::list<Utf8Str>::const_iterator it;
|
---|
492 | size_t i = 0;
|
---|
493 | for (it = aTask->filenames.begin();
|
---|
494 | it != aTask->filenames.end();
|
---|
495 | ++it, ++i)
|
---|
496 | {
|
---|
497 | vrc = RTS3DeleteKey(hS3, m->strBucket.c_str(), (*it).c_str());
|
---|
498 | if (RT_FAILURE(vrc))
|
---|
499 | throw setError(VBOX_E_FILE_ERROR, tr ("Can't delete file '%s' (%Rrc)"), (*it).c_str(), vrc);
|
---|
500 | if (aTask->progress)
|
---|
501 | aTask->progress->SetCurrentOperationProgress((ULONG)(fPercentStep * i));
|
---|
502 | }
|
---|
503 | }
|
---|
504 | catch(HRESULT aRC)
|
---|
505 | {
|
---|
506 | rc = aRC;
|
---|
507 | }
|
---|
508 |
|
---|
509 | aTask->rc = rc;
|
---|
510 |
|
---|
511 | if (hS3 != NULL)
|
---|
512 | RTS3Destroy(hS3);
|
---|
513 |
|
---|
514 | if (!aTask->progress.isNull())
|
---|
515 | aTask->progress->notifyComplete(rc);
|
---|
516 |
|
---|
517 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
518 | LogFlowFuncLeave();
|
---|
519 |
|
---|
520 | return VINF_SUCCESS;
|
---|
521 | }
|
---|
522 |
|
---|
523 | STDMETHODIMP VFSExplorer::Update(IProgress **aProgress)
|
---|
524 | {
|
---|
525 | CheckComArgOutPointerValid(aProgress);
|
---|
526 |
|
---|
527 | AutoCaller autoCaller(this);
|
---|
528 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
529 |
|
---|
530 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
531 |
|
---|
532 | HRESULT rc = S_OK;
|
---|
533 |
|
---|
534 | ComObjPtr<Progress> progress;
|
---|
535 | try
|
---|
536 | {
|
---|
537 | Bstr progressDesc = BstrFmt(tr("Update directory info for '%s'"),
|
---|
538 | m->strPath.c_str());
|
---|
539 | /* Create the progress object */
|
---|
540 | progress.createObject();
|
---|
541 |
|
---|
542 | rc = progress->init(mVirtualBox,
|
---|
543 | static_cast<IVFSExplorer*>(this),
|
---|
544 | progressDesc.raw(),
|
---|
545 | TRUE /* aCancelable */);
|
---|
546 | if (FAILED(rc)) throw rc;
|
---|
547 |
|
---|
548 | /* Initialize our worker task */
|
---|
549 | std::auto_ptr<TaskVFSExplorer> task(new TaskVFSExplorer(TaskVFSExplorer::Update, this, progress));
|
---|
550 |
|
---|
551 | rc = task->startThread();
|
---|
552 | if (FAILED(rc)) throw rc;
|
---|
553 |
|
---|
554 | /* Don't destruct on success */
|
---|
555 | task.release();
|
---|
556 | }
|
---|
557 | catch (HRESULT aRC)
|
---|
558 | {
|
---|
559 | rc = aRC;
|
---|
560 | }
|
---|
561 |
|
---|
562 | if (SUCCEEDED(rc))
|
---|
563 | /* Return progress to the caller */
|
---|
564 | progress.queryInterfaceTo(aProgress);
|
---|
565 |
|
---|
566 | return rc;
|
---|
567 | }
|
---|
568 |
|
---|
569 | STDMETHODIMP VFSExplorer::Cd(IN_BSTR aDir, IProgress **aProgress)
|
---|
570 | {
|
---|
571 | CheckComArgStrNotEmptyOrNull(aDir);
|
---|
572 | CheckComArgOutPointerValid(aProgress);
|
---|
573 |
|
---|
574 | return E_NOTIMPL;
|
---|
575 | }
|
---|
576 |
|
---|
577 | STDMETHODIMP VFSExplorer::CdUp(IProgress **aProgress)
|
---|
578 | {
|
---|
579 | CheckComArgOutPointerValid(aProgress);
|
---|
580 |
|
---|
581 | return E_NOTIMPL;
|
---|
582 | }
|
---|
583 |
|
---|
584 | STDMETHODIMP VFSExplorer::EntryList(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(VFSFileType_T, aTypes))
|
---|
585 | {
|
---|
586 | if (ComSafeArrayOutIsNull(aNames) ||
|
---|
587 | ComSafeArrayOutIsNull(aTypes))
|
---|
588 | return E_POINTER;
|
---|
589 |
|
---|
590 | AutoCaller autoCaller(this);
|
---|
591 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
592 |
|
---|
593 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
594 |
|
---|
595 | com::SafeArray<BSTR> sfaNames((ULONG)m->entryList.size());
|
---|
596 | com::SafeArray<ULONG> sfaTypes((VFSFileType_T)m->entryList.size());
|
---|
597 |
|
---|
598 | std::list<VFSExplorer::Data::DirEntry>::const_iterator it;
|
---|
599 | size_t i = 0;
|
---|
600 | for (it = m->entryList.begin();
|
---|
601 | it != m->entryList.end();
|
---|
602 | ++it, ++i)
|
---|
603 | {
|
---|
604 | const VFSExplorer::Data::DirEntry &entry = (*it);
|
---|
605 | Bstr bstr(entry.name);
|
---|
606 | bstr.cloneTo(&sfaNames[i]);
|
---|
607 | sfaTypes[i] = entry.type;
|
---|
608 | }
|
---|
609 |
|
---|
610 | sfaNames.detachTo(ComSafeArrayOutArg(aNames));
|
---|
611 | sfaTypes.detachTo(ComSafeArrayOutArg(aTypes));
|
---|
612 |
|
---|
613 | return S_OK;
|
---|
614 | }
|
---|
615 |
|
---|
616 | STDMETHODIMP VFSExplorer::Exists(ComSafeArrayIn(IN_BSTR, aNames), ComSafeArrayOut(BSTR, aExists))
|
---|
617 | {
|
---|
618 | CheckComArgSafeArrayNotNull(aNames);
|
---|
619 |
|
---|
620 | AutoCaller autoCaller(this);
|
---|
621 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
622 |
|
---|
623 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
624 |
|
---|
625 | com::SafeArray<IN_BSTR> sfaNames(ComSafeArrayInArg(aNames));
|
---|
626 | std::list<BSTR> listExists;
|
---|
627 |
|
---|
628 | std::list<VFSExplorer::Data::DirEntry>::const_iterator it;
|
---|
629 | for (it = m->entryList.begin();
|
---|
630 | it != m->entryList.end();
|
---|
631 | ++it)
|
---|
632 | {
|
---|
633 | const VFSExplorer::Data::DirEntry &entry = (*it);
|
---|
634 | for (size_t a=0; a < sfaNames.size(); ++a)
|
---|
635 | {
|
---|
636 | if (entry.name == RTPathFilename(Utf8Str(sfaNames[a]).c_str()))
|
---|
637 | {
|
---|
638 | BSTR name;
|
---|
639 | Bstr tmp(sfaNames[a]); /* gcc-3.3 cruft */
|
---|
640 | tmp.cloneTo(&name);
|
---|
641 | listExists.push_back(name);
|
---|
642 | }
|
---|
643 | }
|
---|
644 | }
|
---|
645 |
|
---|
646 | com::SafeArray<BSTR> sfaExists(listExists);
|
---|
647 | sfaExists.detachTo(ComSafeArrayOutArg(aExists));
|
---|
648 |
|
---|
649 | return S_OK;
|
---|
650 | }
|
---|
651 |
|
---|
652 | STDMETHODIMP VFSExplorer::Remove(ComSafeArrayIn(IN_BSTR, aNames), IProgress **aProgress)
|
---|
653 | {
|
---|
654 | CheckComArgSafeArrayNotNull(aNames);
|
---|
655 | CheckComArgOutPointerValid(aProgress);
|
---|
656 |
|
---|
657 | AutoCaller autoCaller(this);
|
---|
658 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
659 |
|
---|
660 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
661 |
|
---|
662 | HRESULT rc = S_OK;
|
---|
663 |
|
---|
664 | com::SafeArray<IN_BSTR> sfaNames(ComSafeArrayInArg(aNames));
|
---|
665 |
|
---|
666 | ComObjPtr<Progress> progress;
|
---|
667 | try
|
---|
668 | {
|
---|
669 | /* Create the progress object */
|
---|
670 | progress.createObject();
|
---|
671 |
|
---|
672 | rc = progress->init(mVirtualBox, static_cast<IVFSExplorer*>(this),
|
---|
673 | Bstr(tr("Delete files")).raw(),
|
---|
674 | TRUE /* aCancelable */);
|
---|
675 | if (FAILED(rc)) throw rc;
|
---|
676 |
|
---|
677 | /* Initialize our worker task */
|
---|
678 | std::auto_ptr<TaskVFSExplorer> task(new TaskVFSExplorer(TaskVFSExplorer::Delete, this, progress));
|
---|
679 |
|
---|
680 | /* Add all filenames to delete as task data */
|
---|
681 | for (size_t a=0; a < sfaNames.size(); ++a)
|
---|
682 | task->filenames.push_back(Utf8Str(sfaNames[a]));
|
---|
683 |
|
---|
684 | rc = task->startThread();
|
---|
685 | if (FAILED(rc)) throw rc;
|
---|
686 |
|
---|
687 | /* Don't destruct on success */
|
---|
688 | task.release();
|
---|
689 | }
|
---|
690 | catch (HRESULT aRC)
|
---|
691 | {
|
---|
692 | rc = aRC;
|
---|
693 | }
|
---|
694 |
|
---|
695 | if (SUCCEEDED(rc))
|
---|
696 | /* Return progress to the caller */
|
---|
697 | progress.queryInterfaceTo(aProgress);
|
---|
698 |
|
---|
699 | return rc;
|
---|
700 | }
|
---|
701 |
|
---|