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.

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

mercurial