diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/poco/Foundation/src/PurgeStrategy.cpp | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/src/PurgeStrategy.cpp')
-rw-r--r-- | contrib/libs/poco/Foundation/src/PurgeStrategy.cpp | 306 |
1 files changed, 153 insertions, 153 deletions
diff --git a/contrib/libs/poco/Foundation/src/PurgeStrategy.cpp b/contrib/libs/poco/Foundation/src/PurgeStrategy.cpp index 070c5c32d5..662d121a15 100644 --- a/contrib/libs/poco/Foundation/src/PurgeStrategy.cpp +++ b/contrib/libs/poco/Foundation/src/PurgeStrategy.cpp @@ -1,153 +1,153 @@ -// -// PurgeStrategy.cpp -// -// Library: Foundation -// Package: Logging -// Module: FileChannel -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#include "Poco/PurgeStrategy.h" -#include "Poco/Path.h" -#include "Poco/DirectoryIterator.h" -#include "Poco/Timestamp.h" - - -namespace Poco { - - -// -// PurgeStrategy -// - - -PurgeStrategy::PurgeStrategy() -{ -} - - -PurgeStrategy::~PurgeStrategy() -{ -} - - -void PurgeStrategy::list(const std::string& path, std::vector<File>& files) -{ - Path p(path); - p.makeAbsolute(); - Path parent = p.parent(); - std::string baseName = p.getFileName(); - baseName.append("."); - - DirectoryIterator it(parent); - DirectoryIterator end; - while (it != end) - { - if (it.name().compare(0, baseName.size(), baseName) == 0) - { - files.push_back(*it); - } - ++it; - } -} - - -// -// PurgeByAgeStrategy -// - - -PurgeByAgeStrategy::PurgeByAgeStrategy(const Timespan& age): _age(age) -{ -} - - -PurgeByAgeStrategy::~PurgeByAgeStrategy() -{ -} - - -void PurgeByAgeStrategy::purge(const std::string& path) -{ - std::vector<File> files; - list(path, files); - for (std::vector<File>::iterator it = files.begin(); it != files.end(); ++it) - { - if (it->getLastModified().isElapsed(_age.totalMicroseconds())) - { - it->remove(); - } - } -} - - -// -// PurgeByCountStrategy -// - - -PurgeByCountStrategy::PurgeByCountStrategy(int count): _count(count) -{ - poco_assert(count > 0); -} - - -PurgeByCountStrategy::~PurgeByCountStrategy() -{ -} - - -void PurgeByCountStrategy::purge(const std::string& path) -{ - std::vector<File> files; - list(path, files); - while (files.size() > _count) - { - std::vector<File>::iterator it = files.begin(); - std::vector<File>::iterator purgeIt = it; - Timestamp purgeTS = purgeIt->getLastModified(); - ++it; - while (it != files.end()) - { - Timestamp md(it->getLastModified()); - if (md <= purgeTS) - { - purgeTS = md; - purgeIt = it; - } - ++it; - } - purgeIt->remove(); - files.erase(purgeIt); - } -} - - -void PurgeOneFileStrategy::purge(const std::string& path) -{ - std::vector<File> files; - list(path, files); - - if (files.empty()) - { - File(path).setSize(0); - return; - } - - auto purge_it = files.begin(); - auto it = files.begin(); - for (++it; it != files.end(); ++it) - if (it->getLastModified() < purge_it->getLastModified()) - purge_it = it; - - purge_it->remove(); -} - - - -} // namespace Poco +// +// PurgeStrategy.cpp +// +// Library: Foundation +// Package: Logging +// Module: FileChannel +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/PurgeStrategy.h" +#include "Poco/Path.h" +#include "Poco/DirectoryIterator.h" +#include "Poco/Timestamp.h" + + +namespace Poco { + + +// +// PurgeStrategy +// + + +PurgeStrategy::PurgeStrategy() +{ +} + + +PurgeStrategy::~PurgeStrategy() +{ +} + + +void PurgeStrategy::list(const std::string& path, std::vector<File>& files) +{ + Path p(path); + p.makeAbsolute(); + Path parent = p.parent(); + std::string baseName = p.getFileName(); + baseName.append("."); + + DirectoryIterator it(parent); + DirectoryIterator end; + while (it != end) + { + if (it.name().compare(0, baseName.size(), baseName) == 0) + { + files.push_back(*it); + } + ++it; + } +} + + +// +// PurgeByAgeStrategy +// + + +PurgeByAgeStrategy::PurgeByAgeStrategy(const Timespan& age): _age(age) +{ +} + + +PurgeByAgeStrategy::~PurgeByAgeStrategy() +{ +} + + +void PurgeByAgeStrategy::purge(const std::string& path) +{ + std::vector<File> files; + list(path, files); + for (std::vector<File>::iterator it = files.begin(); it != files.end(); ++it) + { + if (it->getLastModified().isElapsed(_age.totalMicroseconds())) + { + it->remove(); + } + } +} + + +// +// PurgeByCountStrategy +// + + +PurgeByCountStrategy::PurgeByCountStrategy(int count): _count(count) +{ + poco_assert(count > 0); +} + + +PurgeByCountStrategy::~PurgeByCountStrategy() +{ +} + + +void PurgeByCountStrategy::purge(const std::string& path) +{ + std::vector<File> files; + list(path, files); + while (files.size() > _count) + { + std::vector<File>::iterator it = files.begin(); + std::vector<File>::iterator purgeIt = it; + Timestamp purgeTS = purgeIt->getLastModified(); + ++it; + while (it != files.end()) + { + Timestamp md(it->getLastModified()); + if (md <= purgeTS) + { + purgeTS = md; + purgeIt = it; + } + ++it; + } + purgeIt->remove(); + files.erase(purgeIt); + } +} + + +void PurgeOneFileStrategy::purge(const std::string& path) +{ + std::vector<File> files; + list(path, files); + + if (files.empty()) + { + File(path).setSize(0); + return; + } + + auto purge_it = files.begin(); + auto it = files.begin(); + for (++it; it != files.end(); ++it) + if (it->getLastModified() < purge_it->getLastModified()) + purge_it = it; + + purge_it->remove(); +} + + + +} // namespace Poco |