Changeset 50205 in vbox for trunk/src/VBox/Runtime/common/zip/tar.cpp
- Timestamp:
- Jan 24, 2014 12:49:04 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/zip/tar.cpp
r50194 r50205 110 110 * Only one can be open. */ 111 111 bool fFileOpenForWrite; 112 /** Whether operating in stream mode. */ 113 bool fStreamMode; 114 /** The tar file VFS handle. */ 112 /** The tar file VFS handle (for reading). */ 115 113 RTVFSFILE hVfsFile; 116 114 /** The tar file system VFS handle. */ … … 118 116 /** Set if hVfsFss is at the start of the stream and doesn't need rewinding. */ 119 117 bool fFssAtStart; 120 /** The current stream object (fStreamMode = true). */121 RTVFSIOSTREAM hVfsCur;122 /** The name of the current object (fStreamMode = true). */123 char *pszVfsCurName;124 118 } RTTARINTERNAL; 125 119 /** Pointer to a the internal data of a tar handle. */ … … 194 188 195 189 196 RTR3DECL(int) RTTarOpen(PRTTAR phTar, const char *pszTarname, uint32_t fMode , bool fStream)197 { 198 AssertReturn( !fStream || !(fMode & RTFILE_O_WRITE), VERR_INVALID_PARAMETER);190 RTR3DECL(int) RTTarOpen(PRTTAR phTar, const char *pszTarname, uint32_t fMode) 191 { 192 AssertReturn(fMode & RTFILE_O_WRITE, VERR_INVALID_PARAMETER); 199 193 200 194 /* … … 205 199 return VERR_NO_MEMORY; 206 200 207 pThis->u32Magic = RTTAR_MAGIC; 208 pThis->fOpenMode = fMode; 209 pThis->fStreamMode = fStream && (fMode & RTFILE_O_READ); 201 pThis->u32Magic = RTTAR_MAGIC; 202 pThis->fOpenMode = fMode; 203 pThis->hVfsFile = NIL_RTVFSFILE; 204 pThis->hVfsFss = NIL_RTVFSFSSTREAM; 205 pThis->fFssAtStart = false; 210 206 211 207 /* 212 208 * Open the tar file. 213 209 */ 214 pThis->hVfsFile = NIL_RTVFSFILE; 215 pThis->hVfsFss = NIL_RTVFSFSSTREAM; 216 pThis->fFssAtStart = false; 217 pThis->hVfsCur = NIL_RTVFSIOSTREAM; 218 pThis->pszVfsCurName = NULL; 219 220 int rc; 221 if (!(fMode & RTFILE_O_WRITE)) 222 { 223 rc = RTVfsFileOpenNormal(pszTarname, fMode, &pThis->hVfsFile); 224 if (RT_SUCCESS(rc)) 225 { 226 RTVFSIOSTREAM hVfsIos = RTVfsFileToIoStream(pThis->hVfsFile); 227 rc = RTZipTarFsStreamFromIoStream(hVfsIos, 0 /*fFlags*/, &pThis->hVfsFss); 228 if (RT_SUCCESS(rc)) 229 pThis->fFssAtStart = true; 230 else 231 { 232 RTVfsFileRelease(pThis->hVfsFile); 233 pThis->hVfsFile = NIL_RTVFSFILE; 234 } 235 RTVfsIoStrmRelease(hVfsIos); 236 } 237 } 238 else 239 rc = RTFileOpen(&pThis->hTarFile, pszTarname, fMode); 210 int rc = RTFileOpen(&pThis->hTarFile, pszTarname, fMode); 240 211 if (RT_SUCCESS(rc)) 241 212 { … … 247 218 return rc; 248 219 } 220 249 221 250 222 RTR3DECL(int) RTTarClose(RTTAR hTar) … … 281 253 } 282 254 283 if (pInt->hVfsCur != NIL_RTVFSIOSTREAM)284 {285 RTVfsIoStrmRelease(pInt->hVfsCur);286 pInt->hVfsCur = NIL_RTVFSIOSTREAM;287 }288 289 if (pInt->pszVfsCurName)290 {291 RTStrFree(pInt->pszVfsCurName);292 pInt->pszVfsCurName = NULL;293 }294 295 255 if (pInt->hTarFile != NIL_RTFILE) 296 256 { … … 304 264 305 265 return rc; 306 }307 308 309 RTR3DECL(int) RTTarSeekNextFile(RTTAR hTar)310 {311 PRTTARINTERNAL pInt = hTar;312 RTTAR_VALID_RETURN(pInt);313 314 if (!pInt->fStreamMode)315 return VERR_INVALID_STATE;316 317 /*318 * Release the current object.319 */320 if (pInt->hVfsCur != NIL_RTVFSIOSTREAM)321 {322 RTVfsIoStrmRelease(pInt->hVfsCur);323 pInt->hVfsCur = NIL_RTVFSIOSTREAM;324 }325 326 if (pInt->pszVfsCurName)327 {328 RTStrFree(pInt->pszVfsCurName);329 pInt->pszVfsCurName = NULL;330 }331 332 /*333 * Find the next file.334 */335 for (;;)336 {337 char *pszName;338 RTVFSOBJTYPE enmType;339 RTVFSOBJ hVfsObj;340 int rc = RTVfsFsStrmNext(hTar->hVfsFss, &pszName, &enmType, &hVfsObj);341 if (rc == VERR_EOF)342 return VERR_TAR_END_OF_FILE;343 344 if ( enmType == RTVFSOBJTYPE_FILE345 || enmType == RTVFSOBJTYPE_IO_STREAM346 || enmType == RTVFSOBJTYPE_DIR)347 {348 pInt->pszVfsCurName = pszName;349 if (enmType == RTVFSOBJTYPE_DIR)350 rc = VINF_TAR_DIR_PATH;351 else352 {353 pInt->hVfsCur = RTVfsObjToIoStream(hVfsObj);354 Assert(pInt->hVfsCur != NIL_RTVFSIOSTREAM);355 rc = VINF_SUCCESS;356 }357 RTVfsObjRelease(hVfsObj);358 return rc;359 }360 RTStrFree(pszName);361 RTVfsObjRelease(hVfsObj);362 }363 }364 365 366 RTR3DECL(int) RTTarCurrentFile(RTTAR hTar, char **ppszFilename)367 {368 /* Validate input. */369 AssertPtrNullReturn(ppszFilename, VERR_INVALID_POINTER);370 371 PRTTARINTERNAL pInt = hTar;372 RTTAR_VALID_RETURN(pInt);373 374 if (!pInt->fStreamMode)375 return VERR_INVALID_STATE;376 377 if (!pInt->pszVfsCurName)378 {379 int rc = RTTarSeekNextFile(pInt);380 if (RT_FAILURE(rc))381 return rc;382 }383 Assert(pInt->pszVfsCurName);384 385 if (ppszFilename)386 {387 *ppszFilename = RTStrDup(pInt->pszVfsCurName);388 if (!*ppszFilename)389 return VERR_NO_STR_MEMORY;390 }391 392 return pInt->hVfsCur != NIL_RTVFSIOSTREAM ? VINF_SUCCESS : VINF_TAR_DIR_PATH;393 266 } 394 267 … … 439 312 440 313 441 442 RTR3DECL(int) RTTarFileOpenCurrentFile(RTTAR hTar, PRTTARFILE phFile, char **ppszFilename, uint32_t fOpen)443 {444 /* Validate input. */445 AssertPtrReturn(phFile, VERR_INVALID_POINTER);446 AssertPtrNullReturn(ppszFilename, VERR_INVALID_POINTER);447 AssertReturn((fOpen & RTFILE_O_READ), VERR_INVALID_PARAMETER); /* Only valid in read mode. */448 449 PRTTARINTERNAL pInt = hTar;450 RTTAR_VALID_RETURN(pInt);451 452 if (!pInt->fStreamMode)453 return VERR_INVALID_STATE;454 455 /*456 * Make sure there is a current file (first call w/o RTTarSeekNextFile call).457 */458 if (pInt->hVfsCur == NIL_RTVFSIOSTREAM)459 {460 if (pInt->pszVfsCurName)461 return -VINF_TAR_DIR_PATH;462 463 int rc = RTTarSeekNextFile(pInt);464 if (RT_FAILURE(rc))465 return rc;466 467 if (pInt->hVfsCur == NIL_RTVFSIOSTREAM)468 return -VINF_TAR_DIR_PATH;469 }470 Assert(pInt->pszVfsCurName);471 472 /*473 * Return a copy of the filename if requested.474 */475 if (ppszFilename)476 {477 *ppszFilename = RTStrDup(pInt->pszVfsCurName);478 if (!*ppszFilename)479 return VERR_NO_STR_MEMORY;480 }481 482 /*483 * Create a handle for it.484 */485 int rc = rtTarFileCreateHandleForReadOnly(RTStrDup(pInt->pszVfsCurName), pInt->hVfsCur, RTFILE_O_READ, phFile);486 if (RT_SUCCESS(rc))487 {488 /* Force a RTTarSeekNextFile call the next time around. */489 RTVfsIoStrmRelease(pInt->hVfsCur);490 pInt->hVfsCur = NIL_RTVFSIOSTREAM;491 RTStrFree(pInt->pszVfsCurName);492 pInt->pszVfsCurName = NULL;493 }494 else if (ppszFilename)495 {496 RTStrFree(*ppszFilename);497 *ppszFilename = NULL;498 }499 500 return rc;501 }502 503 504 314 /* Only used for write handles. */ 505 315 static PRTTARFILEINTERNAL rtTarFileCreateForWrite(PRTTARINTERNAL pInt, const char *pszFilename, uint32_t fOpen) … … 526 336 RTR3DECL(int) RTTarFileOpen(RTTAR hTar, PRTTARFILE phFile, const char *pszFilename, uint32_t fOpen) 527 337 { 528 AssertReturn((fOpen & RTFILE_O_READ) || (fOpen & RTFILE_O_WRITE), VERR_INVALID_PARAMETER); 338 /* Write only interface now. */ 339 AssertReturn(fOpen & RTFILE_O_WRITE, VERR_INVALID_PARAMETER); 529 340 530 341 PRTTARINTERNAL pInt = hTar; … … 533 344 if (!pInt->hTarFile) 534 345 return VERR_INVALID_HANDLE; 535 536 if (pInt->fStreamMode)537 return VERR_INVALID_STATE;538 346 539 347 if (fOpen & RTFILE_O_WRITE) … … 565 373 return rc; 566 374 } 567 Assert(pInt->hVfsCur == NIL_RTVFSIOSTREAM && pInt->pszVfsCurName == NULL);568 375 569 376 RTVFSIOSTREAM hVfsIos = RTVfsFileToIoStream(pInt->hVfsFile); … … 910 717 911 718 if ((pFileInt->fOpenMode & RTFILE_O_WRITE) != RTFILE_O_WRITE) 912 return VERR_ WRITE_ERROR;719 return VERR_ACCESS_DENIED; 913 720 914 721 size_t cbTmpWritten = 0;
Note:
See TracChangeset
for help on using the changeset viewer.