blob: 0e4e5e13a867a986ba3900d4e4bf97587a8f5007 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include "WriteBufferFromFileDecorator.h"
#include <IO/WriteBuffer.h>
#include <IO/SwapHelper.h>
namespace DB
{
WriteBufferFromFileDecorator::WriteBufferFromFileDecorator(std::unique_ptr<WriteBuffer> impl_)
: WriteBufferFromFileBase(0, nullptr, 0), impl(std::move(impl_))
{
swap(*impl);
}
void WriteBufferFromFileDecorator::finalizeImpl()
{
/// In case of exception in preFinalize as a part of finalize call
/// WriteBufferFromFileDecorator.finalized is set as true
/// but impl->finalized is remain false
/// That leads to situation when the destructor of impl is called with impl->finalized equal false.
if (!is_prefinalized)
WriteBufferFromFileDecorator::preFinalize();
{
SwapHelper swap(*this, *impl);
impl->finalize();
}
}
WriteBufferFromFileDecorator::~WriteBufferFromFileDecorator()
{
/// It is not a mistake that swap is called here
/// Swap has been called at constructor, it should be called at destructor
/// In oreder to provide valid buffer for impl's d-tor call
swap(*impl);
}
void WriteBufferFromFileDecorator::sync()
{
next();
{
SwapHelper swap(*this, *impl);
impl->sync();
}
}
std::string WriteBufferFromFileDecorator::getFileName() const
{
if (WriteBufferFromFileBase * buffer = dynamic_cast<WriteBufferFromFileBase*>(impl.get()))
return buffer->getFileName();
return std::string();
}
void WriteBufferFromFileDecorator::preFinalize()
{
next();
{
SwapHelper swap(*this, *impl);
impl->preFinalize();
}
is_prefinalized = true;
}
void WriteBufferFromFileDecorator::nextImpl()
{
SwapHelper swap(*this, *impl);
impl->next();
}
}
|