ClickHouse/dbms/include/DB/Storages/DatabaseDropper.h

38 lines
724 B
C
Raw Normal View History

#pragma once
#include <string>
#include <Poco/File.h>
#include <Yandex/logger_useful.h>
/// Удаляет директорию в деструкторе.
class DatabaseDropper
{
public:
DatabaseDropper(const std::string & data_path_) : drop_on_destroy(false), data_path(data_path_) {}
~DatabaseDropper()
{
if (drop_on_destroy)
{
2013-11-18 17:17:45 +00:00
try
{
2013-11-18 17:17:45 +00:00
if (std::uncaught_exception())
LOG_ERROR(&Logger::get("DatabaseDropper"), "Didn't remove database data directory because of uncaught exception.");
2013-11-18 17:17:45 +00:00
else
Poco::File(data_path).remove(false);
}
2013-11-18 17:17:45 +00:00
catch(...)
{
}
}
}
bool drop_on_destroy;
private:
std::string data_path;
};
typedef boost::shared_ptr<DatabaseDropper> DatabaseDropperPtr;