Merge pull request #500 from mikekaganski/master

Fix directory size calculations
This commit is contained in:
Ian Bell
2015-02-24 21:19:46 -07:00
2 changed files with 9 additions and 8 deletions

View File

@@ -117,11 +117,12 @@
{
return (path == L"." || path == L"..");
}
inline unsigned long long CalculateDirSize(const std::wstring &path, std::vector<std::wstring> *errVect = NULL, unsigned long long size = 0)
inline unsigned long long CalculateDirSize(const std::wstring &path, std::vector<std::wstring> *errVect = NULL)
{
WIN32_FIND_DATA data;
unsigned long long size = 0;
WIN32_FIND_DATAW data;
HANDLE sh = NULL;
sh = FindFirstFile((path + L"\\*").c_str(), &data);
sh = FindFirstFileW((path + L"\\*").c_str(), &data);
if (sh == INVALID_HANDLE_VALUE )
{
@@ -137,15 +138,15 @@
if (!IsBrowsePath(data.cFileName))
{
// if found object is ...
if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
// directory, then search it recursievly
size = CalculateDirSize(path + L"\\" + data.cFileName, NULL, size);
size += CalculateDirSize(path + L"\\" + data.cFileName, NULL);
else
// otherwise get object size and add it to directory size
size += (unsigned long long) (data.nFileSizeHigh * (MAXDWORD ) + data.nFileSizeLow);
size += data.nFileSizeHigh * (unsigned long long)(MAXDWORD) + data.nFileSizeLow;
}
} while (FindNextFile(sh, &data)); // do
} while (FindNextFileW(sh, &data)); // do
FindClose(sh);

View File

@@ -17,7 +17,7 @@
#include <stdint.h>
#include <iostream>
static double ftw_summer; // An evil global variable for the ftw function
static thread_local unsigned long long ftw_summer; // An evil global variable for the ftw function
int ftw_function(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf){
ftw_summer += sb->st_size;
return 0; /* To tell nftw() to continue */