Changeset 58212 in vbox for trunk/src/VBox/GuestHost/DragAndDrop/DnDDroppedFiles.cpp
- Timestamp:
- Oct 13, 2015 11:49:33 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/DragAndDrop/DnDDroppedFiles.cpp
r57776 r58212 28 28 #include <VBox/GuestHost/DragAndDrop.h> 29 29 30 #ifdef LOG_GROUP 31 #undef LOG_GROUP 32 #endif 33 #define LOG_GROUP LOG_GROUP_GUEST_DND 34 #include <VBox/log.h> 35 30 36 DnDDroppedFiles::DnDDroppedFiles(void) 31 37 : hDir(NULL) 32 , fOpen( false) { }33 34 DnDDroppedFiles::DnDDroppedFiles(const char *pszPath, uint32_t f Flags)38 , fOpen(0) { } 39 40 DnDDroppedFiles::DnDDroppedFiles(const char *pszPath, uint32_t fOpen) 35 41 : hDir(NULL) 36 , fOpen( false)37 { 38 OpenEx(pszPath, f Flags);42 , fOpen(0) 43 { 44 OpenEx(pszPath, fOpen); 39 45 } 40 46 41 47 DnDDroppedFiles::~DnDDroppedFiles(void) 42 48 { 43 Reset(true /* fRemoveDropDir */); 49 /* Only make sure to not leak any handles and stuff, don't delete any 50 * directories / files here. */ 51 closeInternal(); 44 52 } 45 53 … … 62 70 } 63 71 72 int DnDDroppedFiles::closeInternal(void) 73 { 74 int rc; 75 if (this->hDir != NULL) 76 { 77 rc = RTDirClose(this->hDir); 78 if (RT_SUCCESS(rc)) 79 this->hDir = NULL; 80 } 81 else 82 rc = VINF_SUCCESS; 83 84 LogFlowFuncLeaveRC(rc); 85 return rc; 86 } 87 88 int DnDDroppedFiles::Close(void) 89 { 90 return closeInternal(); 91 } 92 64 93 const char *DnDDroppedFiles::GetDirAbs(void) const 65 94 { … … 69 98 bool DnDDroppedFiles::IsOpen(void) const 70 99 { 71 return this->fOpen;100 return (this->hDir != NULL); 72 101 } 73 102 … … 129 158 this->hDir = phDir; 130 159 this->strPathAbs = pszDropDir; 131 this->fOpen = true;160 this->fOpen = fFlags; 132 161 } 133 162 } … … 135 164 } while (0); 136 165 166 LogFlowFuncLeaveRC(rc); 137 167 return rc; 138 168 } … … 157 187 int DnDDroppedFiles::Reset(bool fRemoveDropDir) 158 188 { 159 int rc = VINF_SUCCESS; 160 if (this->fOpen) 161 { 162 rc = RTDirClose(this->hDir); 163 if (RT_SUCCESS(rc)) 164 { 165 this->fOpen = false; 166 this->hDir = NULL; 167 } 168 } 169 if (RT_SUCCESS(rc)) 170 { 171 this->lstDirs.clear(); 172 this->lstFiles.clear(); 173 174 if ( fRemoveDropDir 175 && this->strPathAbs.isNotEmpty()) 176 { 177 /* Try removing the (empty) drop directory in any case. */ 178 rc = RTDirRemove(this->strPathAbs.c_str()); 179 if (RT_SUCCESS(rc)) /* Only clear if successfully removed. */ 180 this->strPathAbs = ""; 181 } 182 } 183 184 return rc; 189 int rc = closeInternal(); 190 if (RT_SUCCESS(rc)) 191 { 192 if (fRemoveDropDir) 193 { 194 rc = Rollback(); 195 } 196 else 197 { 198 this->lstDirs.clear(); 199 this->lstFiles.clear(); 200 } 201 } 202 203 LogFlowFuncLeaveRC(rc); 204 return rc; 205 } 206 207 int DnDDroppedFiles::Reopen(void) 208 { 209 if (this->strPathAbs.isEmpty()) 210 return VERR_NOT_FOUND; 211 212 return OpenEx(this->strPathAbs.c_str(), this->fOpen); 185 213 } 186 214 … … 190 218 return VINF_SUCCESS; 191 219 192 Assert(this->fOpen);193 Assert(this->hDir != NULL);194 195 220 int rc = VINF_SUCCESS; 196 int rc2;197 221 198 222 /* Rollback by removing any stuff created. 199 223 * Note: Only remove empty directories, never ever delete 200 224 * anything recursive here! Steam (tm) knows best ... :-) */ 225 int rc2; 201 226 for (size_t i = 0; i < this->lstFiles.size(); i++) 202 227 { 203 228 rc2 = RTFileDelete(this->lstFiles.at(i).c_str()); 229 if (RT_SUCCESS(rc2)) 230 this->lstFiles.removeAt(i); 231 232 if (RT_SUCCESS(rc)) 233 rc = rc2; 234 /* Keep going. */ 235 } 236 237 for (size_t i = 0; i < this->lstDirs.size(); i++) 238 { 239 rc2 = RTDirRemove(this->lstDirs.at(i).c_str()); 240 if (RT_SUCCESS(rc2)) 241 this->lstDirs.removeAt(i); 242 204 243 if (RT_SUCCESS(rc)) 205 244 rc = rc2; 206 } 207 208 for (size_t i = 0; i < this->lstDirs.size(); i++) 209 { 210 rc2 = RTDirRemove(this->lstDirs.at(i).c_str()); 211 if (RT_SUCCESS(rc)) 212 rc = rc2; 213 } 214 215 /* Try to remove the empty root dropped files directory as well. */ 216 rc2 = RTDirRemove(this->strPathAbs.c_str()); 245 /* Keep going. */ 246 } 247 248 if (RT_SUCCESS(rc)) 249 { 250 Assert(this->lstFiles.isEmpty()); 251 Assert(this->lstDirs.isEmpty()); 252 253 rc2 = closeInternal(); 254 if (RT_SUCCESS(rc2)) 255 { 256 /* Try to remove the empty root dropped files directory as well. 257 * Might return VERR_DIR_NOT_EMPTY or similar. */ 258 rc2 = RTDirRemove(this->strPathAbs.c_str()); 259 } 260 } 261 217 262 if (RT_SUCCESS(rc)) 218 263 rc = rc2; 219 264 220 return rc; 221 } 222 265 LogFlowFuncLeaveRC(rc); 266 return rc; 267 } 268
Note:
See TracChangeset
for help on using the changeset viewer.