1 | /* $Id: VFSExplorerImpl.cpp 27905 2010-03-31 14:19:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * IVFSExplorer COM class implementations.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include <iprt/dir.h>
|
---|
24 | #include <iprt/path.h>
|
---|
25 | #include <iprt/file.h>
|
---|
26 | #include <iprt/s3.h>
|
---|
27 |
|
---|
28 | #include <VBox/com/array.h>
|
---|
29 |
|
---|
30 | #include <VBox/param.h>
|
---|
31 | #include <VBox/version.h>
|
---|
32 |
|
---|
33 | #include "VFSExplorerImpl.h"
|
---|
34 | #include "VirtualBoxImpl.h"
|
---|
35 | #include "ProgressImpl.h"
|
---|
36 |
|
---|
37 | #include "AutoCaller.h"
|
---|
38 | #include "Logging.h"
|
---|
39 |
|
---|
40 | ////////////////////////////////////////////////////////////////////////////////
|
---|
41 | //
|
---|
42 | // VFSExplorer definitions
|
---|
43 | //
|
---|
44 | ////////////////////////////////////////////////////////////////////////////////
|
---|
45 |
|
---|
46 | /* opaque private instance data of VFSExplorer class */
|
---|
47 | struct VFSExplorer::Data
|
---|
48 | {
|
---|
49 | struct DirEntry
|
---|
50 | {
|
---|
51 | DirEntry(Utf8Str aName, VFSFileType_T aType)
|
---|
52 | : name(aName)
|
---|
53 | , type(aType) {}
|
---|
54 |
|
---|
55 | Utf8Str name;
|
---|
56 | VFSFileType_T type;
|
---|
57 | };
|
---|
58 |
|
---|
59 | VFSType_T storageType;
|
---|
60 | Utf8Str strUsername;
|
---|
61 | Utf8Str strPassword;
|
---|
62 | Utf8Str strHostname;
|
---|
63 | Utf8Str strPath;
|
---|
64 | Utf8Str strBucket;
|
---|
65 |
|
---|
66 | std::list<DirEntry> entryList;
|
---|
67 | };
|
---|
68 |
|
---|
69 | VFSExplorer::VFSExplorer()
|
---|
70 | : mVirtualBox(NULL)
|
---|
71 | {
|
---|
72 | }
|
---|
73 |
|
---|
74 | VFSExplorer::~VFSExplorer()
|
---|
75 | {
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * VFSExplorer COM initializer.
|
---|
81 | * @param
|
---|
82 | * @return
|
---|
83 | */
|
---|
84 | HRESULT VFSExplorer::init(VFSType_T aType, Utf8Str aFilePath, Utf8Str aHostname, Utf8Str aUsername, Utf8Str aPassword, VirtualBox *aVirtualBox)
|
---|
85 | {
|
---|
86 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
87 | AutoInitSpan autoInitSpan(this);
|
---|
88 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
89 |
|
---|
90 | /* Weak reference to a VirtualBox object */
|
---|
91 | unconst(mVirtualBox) = aVirtualBox;
|
---|
92 |
|
---|
93 | /* initialize data */
|
---|
94 | m = new Data;
|
---|
95 |
|
---|
96 | m->storageType = aType;
|
---|
97 | m->strPath = aFilePath;
|
---|
98 | m->strHostname = aHostname;
|
---|
99 | m->strUsername = aUsername;
|
---|
100 | m->strPassword = aPassword;
|
---|
101 |
|
---|
102 | if (m->storageType == VFSType_S3)
|
---|
103 | {
|
---|
104 | size_t bpos = aFilePath.find("/", 1);
|
---|
105 | if (bpos != Utf8Str::npos)
|
---|
106 | {
|
---|
107 | m->strBucket = aFilePath.substr(1, bpos - 1); /* The bucket without any slashes */
|
---|
108 | aFilePath = aFilePath.substr(bpos); /* The rest of the file path */
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | /* Confirm a successful initialization */
|
---|
113 | autoInitSpan.setSucceeded();
|
---|
114 |
|
---|
115 | return S_OK;
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * VFSExplorer COM uninitializer.
|
---|
120 | * @return
|
---|
121 | */
|
---|
122 | void VFSExplorer::uninit()
|
---|
123 | {
|
---|
124 | delete m;
|
---|
125 | m = NULL;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Public method implementation.
|
---|
130 | * @param
|
---|
131 | * @return
|
---|
132 | */
|
---|
133 | STDMETHODIMP VFSExplorer::COMGETTER(Path)(BSTR *aPath)
|
---|
134 | {
|
---|
135 | if (!aPath)
|
---|
136 | return E_POINTER;
|
---|
137 |
|
---|
138 | AutoCaller autoCaller(this);
|
---|
139 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
140 |
|
---|
141 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
142 |
|
---|
143 | Bstr bstrPath(m->strPath);
|
---|
144 | bstrPath.cloneTo(aPath);
|
---|
145 |
|
---|
146 | return S_OK;
|
---|
147 | }
|
---|
148 |
|
---|
149 | STDMETHODIMP VFSExplorer::COMGETTER(Type)(VFSType_T *aType)
|
---|
150 | {
|
---|
151 | if (!aType)
|
---|
152 | return E_POINTER;
|
---|
153 |
|
---|
154 | AutoCaller autoCaller(this);
|
---|
155 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
156 |
|
---|
157 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
158 |
|
---|
159 | *aType = m->storageType;
|
---|
160 |
|
---|
161 | return S_OK;
|
---|
162 | }
|
---|
163 |
|
---|
164 | struct VFSExplorer::TaskVFSExplorer
|
---|
165 | {
|
---|
166 | enum TaskType
|
---|
167 | {
|
---|
168 | Update,
|
---|
169 | Delete
|
---|
170 | };
|
---|
171 |
|
---|
172 | TaskVFSExplorer(TaskType aTaskType, VFSExplorer *aThat, Progress *aProgress)
|
---|
173 | : taskType(aTaskType),
|
---|
174 | pVFSExplorer(aThat),
|
---|
175 | progress(aProgress),
|
---|
176 | rc(S_OK)
|
---|
177 | {}
|
---|
178 | ~TaskVFSExplorer() {}
|
---|
179 |
|
---|
180 | int startThread();
|
---|
181 | static int taskThread(RTTHREAD aThread, void *pvUser);
|
---|
182 | static int uploadProgress(unsigned uPercent, void *pvUser);
|
---|
183 |
|
---|
184 | TaskType taskType;
|
---|
185 | VFSExplorer *pVFSExplorer;
|
---|
186 | ComObjPtr<Progress> progress;
|
---|
187 | HRESULT rc;
|
---|
188 |
|
---|
189 | /* task data */
|
---|
190 | std::list<Utf8Str> filenames;
|
---|
191 | };
|
---|
192 |
|
---|
193 | int VFSExplorer::TaskVFSExplorer::startThread()
|
---|
194 | {
|
---|
195 | int vrc = RTThreadCreate(NULL, VFSExplorer::TaskVFSExplorer::taskThread, this,
|
---|
196 | 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
|
---|
197 | "Explorer::Task");
|
---|
198 |
|
---|
199 | ComAssertMsgRCRet(vrc,
|
---|
200 | ("Could not create taskThreadVFS (%Rrc)\n", vrc), E_FAIL);
|
---|
201 |
|
---|
202 | return vrc;
|
---|
203 | }
|
---|
204 |
|
---|
205 | /* static */
|
---|
206 | DECLCALLBACK(int) VFSExplorer::TaskVFSExplorer::taskThread(RTTHREAD /* aThread */, void *pvUser)
|
---|
207 | {
|
---|
208 | std::auto_ptr<TaskVFSExplorer> task(static_cast<TaskVFSExplorer*>(pvUser));
|
---|
209 | AssertReturn(task.get(), VERR_GENERAL_FAILURE);
|
---|
210 |
|
---|
211 | VFSExplorer *pVFSExplorer = task->pVFSExplorer;
|
---|
212 |
|
---|
213 | LogFlowFuncEnter();
|
---|
214 | LogFlowFunc(("VFSExplorer %p\n", pVFSExplorer));
|
---|
215 |
|
---|
216 | HRESULT rc = S_OK;
|
---|
217 |
|
---|
218 | switch(task->taskType)
|
---|
219 | {
|
---|
220 | case TaskVFSExplorer::Update:
|
---|
221 | {
|
---|
222 | if (pVFSExplorer->m->storageType == VFSType_File)
|
---|
223 | rc = pVFSExplorer->updateFS(task.get());
|
---|
224 | else if (pVFSExplorer->m->storageType == VFSType_S3)
|
---|
225 | rc = pVFSExplorer->updateS3(task.get());
|
---|
226 | break;
|
---|
227 | }
|
---|
228 | case TaskVFSExplorer::Delete:
|
---|
229 | {
|
---|
230 | if (pVFSExplorer->m->storageType == VFSType_File)
|
---|
231 | rc = pVFSExplorer->deleteFS(task.get());
|
---|
232 | else if (pVFSExplorer->m->storageType == VFSType_S3)
|
---|
233 | rc = pVFSExplorer->deleteS3(task.get());
|
---|
234 | break;
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
239 | LogFlowFuncLeave();
|
---|
240 |
|
---|
241 | return VINF_SUCCESS;
|
---|
242 | }
|
---|
243 |
|
---|
244 | /* static */
|
---|
245 | int VFSExplorer::TaskVFSExplorer::uploadProgress(unsigned uPercent, void *pvUser)
|
---|
246 | {
|
---|
247 | VFSExplorer::TaskVFSExplorer* pTask = *(VFSExplorer::TaskVFSExplorer**)pvUser;
|
---|
248 |
|
---|
249 | if (pTask &&
|
---|
250 | !pTask->progress.isNull())
|
---|
251 | {
|
---|
252 | BOOL fCanceled;
|
---|
253 | pTask->progress->COMGETTER(Canceled)(&fCanceled);
|
---|
254 | if (fCanceled)
|
---|
255 | return -1;
|
---|
256 | pTask->progress->SetCurrentOperationProgress(uPercent);
|
---|
257 | }
|
---|
258 | return VINF_SUCCESS;
|
---|
259 | }
|
---|
260 |
|
---|
261 | VFSFileType_T VFSExplorer::RTToVFSFileType(int aType) const
|
---|
262 | {
|
---|
263 | VFSFileType_T t;
|
---|
264 | switch(aType)
|
---|
265 | {
|
---|
266 | default:
|
---|
267 | case RTDIRENTRYTYPE_UNKNOWN: t = VFSFileType_Unknown; break;
|
---|
268 | case RTDIRENTRYTYPE_FIFO: t = VFSFileType_Fifo; break;
|
---|
269 | case RTDIRENTRYTYPE_DEV_CHAR: t = VFSFileType_DevChar; break;
|
---|
270 | case RTDIRENTRYTYPE_DIRECTORY: t = VFSFileType_Directory; break;
|
---|
271 | case RTDIRENTRYTYPE_DEV_BLOCK: t = VFSFileType_DevBlock; break;
|
---|
272 | case RTDIRENTRYTYPE_FILE: t = VFSFileType_File; break;
|
---|
273 | case RTDIRENTRYTYPE_SYMLINK: t = VFSFileType_SymLink; break;
|
---|
274 | case RTDIRENTRYTYPE_SOCKET: t = VFSFileType_Socket; break;
|
---|
275 | case RTDIRENTRYTYPE_WHITEOUT: t = VFSFileType_WhiteOut; break;
|
---|
276 | }
|
---|
277 | return t;
|
---|
278 | }
|
---|
279 |
|
---|
280 | HRESULT VFSExplorer::updateFS(TaskVFSExplorer *aTask)
|
---|
281 | {
|
---|
282 | LogFlowFuncEnter();
|
---|
283 |
|
---|
284 | AutoCaller autoCaller(this);
|
---|
285 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
286 |
|
---|
287 | AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
288 |
|
---|
289 | HRESULT rc = S_OK;
|
---|
290 |
|
---|
291 | std::list<VFSExplorer::Data::DirEntry> fileList;
|
---|
292 | char *pszPath = NULL;
|
---|
293 | PRTDIR pDir = NULL;
|
---|
294 | try
|
---|
295 | {
|
---|
296 | pszPath = RTStrDup(m->strPath.c_str());
|
---|
297 | RTPathStripFilename(pszPath);
|
---|
298 | int vrc = RTDirOpen(&pDir, pszPath);
|
---|
299 | if (RT_FAILURE(vrc))
|
---|
300 | throw setError(VBOX_E_FILE_ERROR, tr ("Can't open directory '%s' (%Rrc)"), pszPath, vrc);
|
---|
301 |
|
---|
302 | if (aTask->progress)
|
---|
303 | aTask->progress->SetCurrentOperationProgress(33);
|
---|
304 | RTDIRENTRY entry;
|
---|
305 | while (RT_SUCCESS(vrc))
|
---|
306 | {
|
---|
307 | vrc = RTDirRead(pDir, &entry, NULL);
|
---|
308 | if (RT_SUCCESS(vrc))
|
---|
309 | {
|
---|
310 | Utf8Str name(entry.szName);
|
---|
311 | if (name != "." &&
|
---|
312 | name != "..")
|
---|
313 | fileList.push_back(VFSExplorer::Data::DirEntry(name, RTToVFSFileType(entry.enmType)));
|
---|
314 | }
|
---|
315 | }
|
---|
316 | if (aTask->progress)
|
---|
317 | aTask->progress->SetCurrentOperationProgress(66);
|
---|
318 | }
|
---|
319 | catch(HRESULT aRC)
|
---|
320 | {
|
---|
321 | rc = aRC;
|
---|
322 | }
|
---|
323 |
|
---|
324 | /* Clean up */
|
---|
325 | if (pszPath)
|
---|
326 | RTStrFree(pszPath);
|
---|
327 | if (pDir)
|
---|
328 | RTDirClose(pDir);
|
---|
329 |
|
---|
330 | if (aTask->progress)
|
---|
331 | aTask->progress->SetCurrentOperationProgress(99);
|
---|
332 |
|
---|
333 | /* Assign the result on success (this clears the old list) */
|
---|
334 | if (rc == S_OK)
|
---|
335 | m->entryList.assign(fileList.begin(), fileList.end());
|
---|
336 |
|
---|
337 | aTask->rc = rc;
|
---|
338 |
|
---|
339 | if (!aTask->progress.isNull())
|
---|
340 | aTask->progress->notifyComplete(rc);
|
---|
341 |
|
---|
342 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
343 | LogFlowFuncLeave();
|
---|
344 |
|
---|
345 | return VINF_SUCCESS;
|
---|
346 | }
|
---|
347 |
|
---|
348 | HRESULT VFSExplorer::deleteFS(TaskVFSExplorer *aTask)
|
---|
349 | {
|
---|
350 | LogFlowFuncEnter();
|
---|
351 |
|
---|
352 | AutoCaller autoCaller(this);
|
---|
353 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
354 |
|
---|
355 | AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
356 |
|
---|
357 | HRESULT rc = S_OK;
|
---|
358 |
|
---|
359 | float fPercentStep = 100.0f / aTask->filenames.size();
|
---|
360 | try
|
---|
361 | {
|
---|
362 | char szPath[RTPATH_MAX];
|
---|
363 | std::list<Utf8Str>::const_iterator it;
|
---|
364 | size_t i = 0;
|
---|
365 | for (it = aTask->filenames.begin();
|
---|
366 | it != aTask->filenames.end();
|
---|
367 | ++it, ++i)
|
---|
368 | {
|
---|
369 | memcpy(szPath, m->strPath.c_str(), strlen(m->strPath.c_str()) + 1);
|
---|
370 | RTPathStripFilename(szPath);
|
---|
371 | RTPathAppend(szPath, sizeof(szPath), (*it).c_str());
|
---|
372 | int vrc = RTFileDelete(szPath);
|
---|
373 | if (RT_FAILURE(vrc))
|
---|
374 | throw setError(VBOX_E_FILE_ERROR, tr ("Can't delete file '%s' (%Rrc)"), szPath, vrc);
|
---|
375 | if (aTask->progress)
|
---|
376 | aTask->progress->SetCurrentOperationProgress((ULONG)(fPercentStep * i));
|
---|
377 | }
|
---|
378 | }
|
---|
379 | catch(HRESULT aRC)
|
---|
380 | {
|
---|
381 | rc = aRC;
|
---|
382 | }
|
---|
383 |
|
---|
384 | aTask->rc = rc;
|
---|
385 |
|
---|
386 | if (!aTask->progress.isNull())
|
---|
387 | aTask->progress->notifyComplete(rc);
|
---|
388 |
|
---|
389 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
390 | LogFlowFuncLeave();
|
---|
391 |
|
---|
392 | return VINF_SUCCESS;
|
---|
393 | }
|
---|
394 |
|
---|
395 | HRESULT VFSExplorer::updateS3(TaskVFSExplorer *aTask)
|
---|
396 | {
|
---|
397 | LogFlowFuncEnter();
|
---|
398 |
|
---|
399 | AutoCaller autoCaller(this);
|
---|
400 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
401 |
|
---|
402 | AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
403 |
|
---|
404 | HRESULT rc = S_OK;
|
---|
405 |
|
---|
406 | RTS3 hS3 = NULL;
|
---|
407 | std::list<VFSExplorer::Data::DirEntry> fileList;
|
---|
408 | try
|
---|
409 | {
|
---|
410 | int vrc = RTS3Create(&hS3, m->strUsername.c_str(), m->strPassword.c_str(), m->strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
|
---|
411 | if (RT_FAILURE(vrc))
|
---|
412 | throw setError(E_FAIL, tr ("Can't open S3 storage service (%Rrc)"), vrc);
|
---|
413 |
|
---|
414 | RTS3SetProgressCallback(hS3, VFSExplorer::TaskVFSExplorer::uploadProgress, &aTask);
|
---|
415 | /* Do we need the list of buckets or keys? */
|
---|
416 | if (m->strBucket.isEmpty())
|
---|
417 | {
|
---|
418 | PCRTS3BUCKETENTRY pBuckets = NULL;
|
---|
419 | vrc = RTS3GetBuckets(hS3, &pBuckets);
|
---|
420 | if (RT_FAILURE(vrc))
|
---|
421 | throw setError(E_FAIL, tr ("Can't get buckets (%Rrc)"), vrc);
|
---|
422 |
|
---|
423 | PCRTS3BUCKETENTRY pTmpBuckets = pBuckets;
|
---|
424 | while (pBuckets)
|
---|
425 | {
|
---|
426 | fileList.push_back(VFSExplorer::Data::DirEntry(pBuckets->pszName, VFSFileType_Directory));
|
---|
427 | pBuckets = pBuckets->pNext;
|
---|
428 | }
|
---|
429 | RTS3BucketsDestroy(pTmpBuckets);
|
---|
430 | }
|
---|
431 | else
|
---|
432 | {
|
---|
433 | PCRTS3KEYENTRY pKeys = NULL;
|
---|
434 | vrc = RTS3GetBucketKeys(hS3, m->strBucket.c_str(), &pKeys);
|
---|
435 | if (RT_FAILURE(vrc))
|
---|
436 | throw setError(E_FAIL, tr ("Can't get keys for bucket (%Rrc)"), vrc);
|
---|
437 |
|
---|
438 | PCRTS3KEYENTRY pTmpKeys = pKeys;
|
---|
439 | while (pKeys)
|
---|
440 | {
|
---|
441 | Utf8Str name(pKeys->pszName);
|
---|
442 | fileList.push_back(VFSExplorer::Data::DirEntry(pKeys->pszName, VFSFileType_File));
|
---|
443 | pKeys = pKeys->pNext;
|
---|
444 | }
|
---|
445 | RTS3KeysDestroy(pTmpKeys);
|
---|
446 | }
|
---|
447 | }
|
---|
448 | catch(HRESULT aRC)
|
---|
449 | {
|
---|
450 | rc = aRC;
|
---|
451 | }
|
---|
452 |
|
---|
453 | if (hS3 != NULL)
|
---|
454 | RTS3Destroy(hS3);
|
---|
455 |
|
---|
456 | /* Assign the result on success (this clears the old list) */
|
---|
457 | if (rc == S_OK)
|
---|
458 | m->entryList.assign(fileList.begin(), fileList.end());
|
---|
459 |
|
---|
460 | aTask->rc = rc;
|
---|
461 |
|
---|
462 | if (!aTask->progress.isNull())
|
---|
463 | aTask->progress->notifyComplete(rc);
|
---|
464 |
|
---|
465 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
466 | LogFlowFuncLeave();
|
---|
467 |
|
---|
468 | return VINF_SUCCESS;
|
---|
469 | }
|
---|
470 |
|
---|
471 | HRESULT VFSExplorer::deleteS3(TaskVFSExplorer *aTask)
|
---|
472 | {
|
---|
473 | LogFlowFuncEnter();
|
---|
474 |
|
---|
475 | AutoCaller autoCaller(this);
|
---|
476 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
477 |
|
---|
478 | AutoWriteLock appLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
479 |
|
---|
480 | HRESULT rc = S_OK;
|
---|
481 |
|
---|
482 | RTS3 hS3 = NULL;
|
---|
483 | float fPercentStep = 100.0f / aTask->filenames.size();
|
---|
484 | try
|
---|
485 | {
|
---|
486 | int vrc = RTS3Create(&hS3, m->strUsername.c_str(), m->strPassword.c_str(), m->strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
|
---|
487 | if (RT_FAILURE(vrc))
|
---|
488 | throw setError(E_FAIL, tr ("Can't open S3 storage service (%Rrc)"), vrc);
|
---|
489 |
|
---|
490 | RTS3SetProgressCallback(hS3, VFSExplorer::TaskVFSExplorer::uploadProgress, &aTask);
|
---|
491 |
|
---|
492 | std::list<Utf8Str>::const_iterator it;
|
---|
493 | size_t i = 0;
|
---|
494 | for (it = aTask->filenames.begin();
|
---|
495 | it != aTask->filenames.end();
|
---|
496 | ++it, ++i)
|
---|
497 | {
|
---|
498 | vrc = RTS3DeleteKey(hS3, m->strBucket.c_str(), (*it).c_str());
|
---|
499 | if (RT_FAILURE(vrc))
|
---|
500 | throw setError(VBOX_E_FILE_ERROR, tr ("Can't delete file '%s' (%Rrc)"), (*it).c_str(), vrc);
|
---|
501 | if (aTask->progress)
|
---|
502 | aTask->progress->SetCurrentOperationProgress((ULONG)(fPercentStep * i));
|
---|
503 | }
|
---|
504 | }
|
---|
505 | catch(HRESULT aRC)
|
---|
506 | {
|
---|
507 | rc = aRC;
|
---|
508 | }
|
---|
509 |
|
---|
510 | aTask->rc = rc;
|
---|
511 |
|
---|
512 | if (hS3 != NULL)
|
---|
513 | RTS3Destroy(hS3);
|
---|
514 |
|
---|
515 | if (!aTask->progress.isNull())
|
---|
516 | aTask->progress->notifyComplete(rc);
|
---|
517 |
|
---|
518 | LogFlowFunc(("rc=%Rhrc\n", rc));
|
---|
519 | LogFlowFuncLeave();
|
---|
520 |
|
---|
521 | return VINF_SUCCESS;
|
---|
522 | }
|
---|
523 |
|
---|
524 | STDMETHODIMP VFSExplorer::Update(IProgress **aProgress)
|
---|
525 | {
|
---|
526 | CheckComArgOutPointerValid(aProgress);
|
---|
527 |
|
---|
528 | AutoCaller autoCaller(this);
|
---|
529 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
530 |
|
---|
531 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
532 |
|
---|
533 | HRESULT rc = S_OK;
|
---|
534 |
|
---|
535 | ComObjPtr<Progress> progress;
|
---|
536 | try
|
---|
537 | {
|
---|
538 | Bstr progressDesc = BstrFmt(tr("Update directory info for '%s'"),
|
---|
539 | m->strPath.raw());
|
---|
540 | /* Create the progress object */
|
---|
541 | progress.createObject();
|
---|
542 |
|
---|
543 | rc = progress->init(mVirtualBox, static_cast<IVFSExplorer*>(this),
|
---|
544 | progressDesc,
|
---|
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")),
|
---|
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 |
|
---|