[MinidumpUpload] Only upload small dumps

This commit is contained in:
momo5502 2017-02-10 21:46:03 +01:00
parent e72a60c19e
commit ef675d4d87
3 changed files with 22 additions and 5 deletions

View File

@ -240,12 +240,14 @@ namespace Components
{ {
do do
{ {
if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0) if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) continue; // ignore directory
continue; // ignore directory
char fullPath[MAX_PATH_SIZE]; char fullPath[MAX_PATH_SIZE];
PathCombineA(fullPath, MinidumpUpload::queuedMinidumpsFolder.data(), ffd.cFileName); PathCombineA(fullPath, MinidumpUpload::queuedMinidumpsFolder.data(), ffd.cFileName);
// Only upload if less than 5MB
if(Utils::IO::FileSize(fullPath) > (5 * 1024 * 1024)) continue;
// Try to open this minidump // Try to open this minidump
Logger::Print("Trying to upload %s...\n", fullPath); Logger::Print("Trying to upload %s...\n", fullPath);
auto minidump = Minidump::Open(fullPath); auto minidump = Minidump::Open(fullPath);
@ -268,7 +270,7 @@ namespace Components
// Delete minidump if possible // Delete minidump if possible
DeleteFileA(fullPath); DeleteFileA(fullPath);
#endif #endif
} while (FindNextFileA(hFind, &ffd) != 0); } while (FindNextFileA(hFind, &ffd));
} }
Logger::Print("All minidumps uploaded.\n"); Logger::Print("All minidumps uploaded.\n");

View File

@ -57,13 +57,27 @@ namespace Utils
stream.close(); stream.close();
return true; return true;
} }
stream.close();
} }
return false; return false;
} }
size_t FileSize(std::string file)
{
if (FileExists(file))
{
std::ifstream stream(file, std::ios::binary);
if(stream.good())
{
stream.seekg(0, std::ios::end);
return static_cast<size_t>(stream.tellg());
}
}
return 0;
}
bool CreateDirectory(std::string dir) bool CreateDirectory(std::string dir)
{ {
return std::experimental::filesystem::create_directories(dir); return std::experimental::filesystem::create_directories(dir);

View File

@ -7,6 +7,7 @@ namespace Utils
bool FileExists(std::string file); bool FileExists(std::string file);
bool WriteFile(std::string file, std::string data, bool append = false); bool WriteFile(std::string file, std::string data, bool append = false);
bool ReadFile(std::string file, std::string* data); bool ReadFile(std::string file, std::string* data);
size_t FileSize(std::string file);
std::string ReadFile(std::string file); std::string ReadFile(std::string file);
bool CreateDirectory(std::string dir); bool CreateDirectory(std::string dir);
std::vector<std::string> ListFiles(std::string dir); std::vector<std::string> ListFiles(std::string dir);