toolkit/crashreporter/client/crashreporter_unix_common.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "crashreporter.h"
michael@0 6
michael@0 7 #include <dirent.h>
michael@0 8 #include <sys/stat.h>
michael@0 9 #include <errno.h>
michael@0 10 #include <algorithm>
michael@0 11
michael@0 12 using namespace CrashReporter;
michael@0 13 using std::string;
michael@0 14 using std::vector;
michael@0 15 using std::sort;
michael@0 16
michael@0 17 struct FileData
michael@0 18 {
michael@0 19 time_t timestamp;
michael@0 20 string path;
michael@0 21 };
michael@0 22
michael@0 23 static bool CompareFDTime(const FileData& fd1, const FileData& fd2)
michael@0 24 {
michael@0 25 return fd1.timestamp > fd2.timestamp;
michael@0 26 }
michael@0 27
michael@0 28 void UIPruneSavedDumps(const std::string& directory)
michael@0 29 {
michael@0 30 DIR *dirfd = opendir(directory.c_str());
michael@0 31 if (!dirfd)
michael@0 32 return;
michael@0 33
michael@0 34 vector<FileData> dumpfiles;
michael@0 35
michael@0 36 while (dirent *dir = readdir(dirfd)) {
michael@0 37 FileData fd;
michael@0 38 fd.path = directory + '/' + dir->d_name;
michael@0 39 if (fd.path.size() < 5)
michael@0 40 continue;
michael@0 41
michael@0 42 if (fd.path.compare(fd.path.size() - 4, 4, ".dmp") != 0)
michael@0 43 continue;
michael@0 44
michael@0 45 struct stat st;
michael@0 46 if (stat(fd.path.c_str(), &st)) {
michael@0 47 closedir(dirfd);
michael@0 48 return;
michael@0 49 }
michael@0 50
michael@0 51 fd.timestamp = st.st_mtime;
michael@0 52
michael@0 53 dumpfiles.push_back(fd);
michael@0 54 }
michael@0 55
michael@0 56 sort(dumpfiles.begin(), dumpfiles.end(), CompareFDTime);
michael@0 57
michael@0 58 while (dumpfiles.size() > kSaveCount) {
michael@0 59 // get the path of the oldest file
michael@0 60 string path = dumpfiles[dumpfiles.size() - 1].path;
michael@0 61 UIDeleteFile(path.c_str());
michael@0 62
michael@0 63 // s/.dmp/.extra/
michael@0 64 path.replace(path.size() - 4, 4, ".extra");
michael@0 65 UIDeleteFile(path.c_str());
michael@0 66
michael@0 67 dumpfiles.pop_back();
michael@0 68 }
michael@0 69 }

mercurial