Changeset 30079 in vbox for trunk/src/VBox/Runtime/common/checksum
- Timestamp:
- Jun 7, 2010 2:57:44 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 62451
- Location:
- trunk/src/VBox/Runtime/common/checksum
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/checksum/RTSha1Digest.cpp
r29901 r30079 5 5 6 6 /* 7 * Copyright (C) 2009 Oracle Corporation7 * Copyright (C) 2009-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 #include <iprt/sha.h> 33 33 34 #include <iprt/alloca.h> 34 35 #include <iprt/assert.h> 35 36 #include <iprt/mem.h> … … 39 40 #include <openssl/sha.h> 40 41 41 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, PFNRTSHAPROGRESS pfnProgressCallback, void *pvUser) 42 43 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, FNRTPROGRESS pfnProgressCallback, void *pvUser) 42 44 { 43 45 /* Validate input */ … … 47 49 48 50 *ppszDigest = NULL; 49 int rc = VINF_SUCCESS;50 51 51 /* Initialize OpenSSL */52 /* Initialize OpenSSL. */ 52 53 SHA_CTX ctx; 53 54 if (!SHA1_Init(&ctx)) 54 55 return VERR_INTERNAL_ERROR; 55 56 57 /* Open the file to calculate a SHA1 sum of */ 58 RTFILE hFile; 59 int rc = RTFileOpen(&hFile, pszFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE); 60 if (RT_FAILURE(rc)) 61 return rc; 62 56 63 /* Fetch the file size. Only needed if there is a progress callback. */ 57 float multi = 0;64 double rdMulti = 0; 58 65 if (pfnProgressCallback) 59 66 { 60 67 uint64_t cbFile; 61 rc = RTFile QuerySize(pszFile, &cbFile);68 rc = RTFileGetSize(hFile, &cbFile); 62 69 if (RT_FAILURE(rc)) 70 { 71 RTFileClose(hFile); 63 72 return rc; 64 multi = 100.0 / cbFile; 73 } 74 rdMulti = 100.0 / cbFile; 65 75 } 66 76 67 /* Open the file to calculate a SHA1 sum of */ 68 RTFILE file; 69 rc = RTFileOpen(&file, pszFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE); 70 if (RT_FAILURE(rc)) 71 return rc; 77 /* Allocate a reasonably large buffer, fall back on a tiny one. */ 78 void *pvBufFree; 79 size_t cbBuf = _1M; 80 void *pvBuf = pvBufFree = RTMemTmpAlloc(cbBuf); 81 if (!pvBuf) 82 { 83 cbBuf = 0x1000; 84 pvBuf = alloca(cbBuf); 85 } 72 86 73 87 /* Read that file in blocks */ 74 void *pvBuf = RTMemTmpAlloc(_1M);75 if (!pvBuf)76 {77 RTFileClose(file);78 rc = VERR_NO_MEMORY;79 }80 88 size_t cbRead; 81 size_t cbRead Full = 0;89 size_t cbReadTotal = 0; 82 90 for (;;) 83 91 { 84 cbRead = 0; 85 rc = RTFileRead(file, pvBuf, _1M, &cbRead); 92 rc = RTFileRead(hFile, pvBuf, cbBuf, &cbRead); 86 93 if (RT_FAILURE(rc) || !cbRead) 87 94 break; … … 91 98 break; 92 99 } 93 cbRead Full += cbRead;94 /* Call progress callback if some is defined */ 95 if ( pfnProgressCallback96 && RT_FAILURE(pfnProgressCallback((unsigned)(cbReadFull * multi), pvUser)))100 cbReadTotal += cbRead; 101 102 /* Call the progress callback if one is defined */ 103 if (pfnProgressCallback) 97 104 { 98 /* Cancel support */99 rc = VERR_CANCELLED;100 break;105 rc = pfnProgressCallback((unsigned)(cbReadTotal * rdMulti), pvUser); 106 if (RT_FAILURE(rc)) 107 break; /* canceled */ 101 108 } 102 109 } 103 RTMemTmpFree(pvBuf );104 RTFileClose( file);110 RTMemTmpFree(pvBufFree); 111 RTFileClose(hFile); 105 112 106 113 if (RT_FAILURE(rc)) -
trunk/src/VBox/Runtime/common/checksum/manifest.cpp
r29904 r30079 60 60 typedef struct RTMANIFESTCALLBACKDATA 61 61 { 62 PFNRT MANIFESTPROGRESS pfnProgressCallback;62 PFNRTPROGRESS pfnProgressCallback; 63 63 void *pvUser; 64 64 size_t cMaxFiles; … … 67 67 typedef RTMANIFESTCALLBACKDATA* PRTMANIFESTCALLBACKDATA; 68 68 69 69 70 int rtSHAProgressCallback(unsigned uPercent, void *pvUser) 70 71 { 71 72 PRTMANIFESTCALLBACKDATA pData = (PRTMANIFESTCALLBACKDATA)pvUser; 72 return pData->pfnProgressCallback((unsigned)((uPercent + (float)pData->cCurrentFile * 100.0) / (float)pData->cMaxFiles), pData->pvUser); 73 return pData->pfnProgressCallback((unsigned)( (uPercent + (float)pData->cCurrentFile * 100.0) 74 / (float)pData->cMaxFiles), 75 pData->pvUser); 73 76 } 74 77 … … 227 230 228 231 229 RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser) 232 RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed, 233 PFNRTPROGRESS pfnProgressCallback, void *pvUser) 230 234 { 231 235 /* Validate input */ … … 275 279 276 280 277 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser) 281 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, 282 PFNRTPROGRESS pfnProgressCallback, void *pvUser) 278 283 { 279 284 /* Validate input */
Note:
See TracChangeset
for help on using the changeset viewer.