2021-10-21 14:29:15 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2023-05-11 06:47:33 -05:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
2021-10-21 14:29:15 -05:00
|
|
|
|
|
|
|
class DocumentBroker;
|
2023-05-08 06:57:30 -05:00
|
|
|
|
|
|
|
class Quarantine
|
2021-10-21 14:29:15 -05:00
|
|
|
{
|
2023-05-08 06:57:30 -05:00
|
|
|
public:
|
2023-05-11 05:48:40 -05:00
|
|
|
Quarantine(DocumentBroker& docBroker);
|
2023-05-08 07:11:01 -05:00
|
|
|
|
2023-05-08 06:57:30 -05:00
|
|
|
static void initialize(const std::string& path);
|
2021-10-21 14:29:15 -05:00
|
|
|
|
2023-05-11 05:57:31 -05:00
|
|
|
void setDocumentName(const std::string& docName) { _docName = docName; }
|
|
|
|
|
2023-05-08 07:11:01 -05:00
|
|
|
bool quarantineFile(const std::string& docName);
|
2023-04-21 18:28:23 -05:00
|
|
|
|
|
|
|
/// Removes the quarantined files for the given DocKey when we unload gracefully.
|
2023-05-08 07:11:01 -05:00
|
|
|
void removeQuarantinedFiles();
|
2023-05-08 06:57:30 -05:00
|
|
|
|
|
|
|
private:
|
2023-05-08 07:11:01 -05:00
|
|
|
bool isQuarantineEnabled() const { return !QuarantinePath.empty(); }
|
2023-05-08 06:57:30 -05:00
|
|
|
|
2023-05-08 07:11:01 -05:00
|
|
|
std::size_t quarantineSize();
|
2023-05-08 06:57:30 -05:00
|
|
|
|
2023-05-08 07:11:01 -05:00
|
|
|
void makeQuarantineSpace();
|
2023-05-08 06:57:30 -05:00
|
|
|
|
2023-05-11 05:46:16 -05:00
|
|
|
void clearOldQuarantineVersions();
|
2023-05-08 06:57:30 -05:00
|
|
|
|
2023-05-08 07:11:01 -05:00
|
|
|
void removeQuarantine();
|
2023-05-08 06:57:30 -05:00
|
|
|
|
|
|
|
private:
|
2023-05-11 06:47:33 -05:00
|
|
|
static std::unordered_map<std::string, std::vector<std::string>> QuarantineMap;
|
2023-05-08 06:57:30 -05:00
|
|
|
static std::string QuarantinePath;
|
2023-05-08 07:11:01 -05:00
|
|
|
|
2023-05-11 05:58:15 -05:00
|
|
|
const std::string _docKey;
|
2023-05-11 05:48:40 -05:00
|
|
|
const std::string _quarantinedFilenamePrefix;
|
2023-05-11 06:00:39 -05:00
|
|
|
const std::size_t _maxSizeBytes;
|
2023-05-11 06:07:16 -05:00
|
|
|
const std::size_t _maxAgeSecs;
|
2023-05-11 06:36:12 -05:00
|
|
|
const std::size_t _maxVersions;
|
2023-05-11 05:48:40 -05:00
|
|
|
std::string _docName;
|
2023-05-08 06:57:30 -05:00
|
|
|
};
|