2021-08-18 22:19:14 +00:00
|
|
|
#include <Disks/TemporaryFileOnDisk.h>
|
|
|
|
#include <Disks/IDisk.h>
|
|
|
|
#include <Poco/TemporaryFile.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
TemporaryFileOnDisk::TemporaryFileOnDisk(const DiskPtr & disk_, const String & prefix_)
|
|
|
|
: disk(disk_)
|
|
|
|
{
|
|
|
|
String dummy_prefix = "a/";
|
|
|
|
filepath = Poco::TemporaryFile::tempName(dummy_prefix);
|
|
|
|
dummy_prefix += "tmp";
|
|
|
|
assert(filepath.starts_with(dummy_prefix));
|
|
|
|
filepath.replace(0, dummy_prefix.length(), prefix_);
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryFileOnDisk::~TemporaryFileOnDisk()
|
|
|
|
{
|
2022-04-12 15:09:09 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (disk && !filepath.empty() && disk->exists(filepath))
|
|
|
|
disk->removeRecursive(filepath);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
}
|
2021-08-18 22:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|