add noremove option to TempFile
This commit is contained in:
parent
2d5c2a8058
commit
4ceb46b13d
@ -148,6 +148,7 @@ bool maketmpdir(string& tdir, string& reason)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TempFileInternal::TempFileInternal(const string& suffix)
|
TempFileInternal::TempFileInternal(const string& suffix)
|
||||||
|
: m_noremove(false)
|
||||||
{
|
{
|
||||||
string filename = path_cat(tmplocation(), "rcltmpfXXXXXX");
|
string filename = path_cat(tmplocation(), "rcltmpfXXXXXX");
|
||||||
char *cp = strdup(filename.c_str());
|
char *cp = strdup(filename.c_str());
|
||||||
@ -179,7 +180,7 @@ TempFileInternal::TempFileInternal(const string& suffix)
|
|||||||
|
|
||||||
TempFileInternal::~TempFileInternal()
|
TempFileInternal::~TempFileInternal()
|
||||||
{
|
{
|
||||||
if (!m_filename.empty())
|
if (!m_filename.empty() && !m_noremove)
|
||||||
unlink(m_filename.c_str());
|
unlink(m_filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,12 +85,26 @@ class TempFileInternal {
|
|||||||
public:
|
public:
|
||||||
TempFileInternal(const string& suffix);
|
TempFileInternal(const string& suffix);
|
||||||
~TempFileInternal();
|
~TempFileInternal();
|
||||||
const char *filename() {return m_filename.c_str();}
|
const char *filename()
|
||||||
const string &getreason() {return m_reason;}
|
{
|
||||||
bool ok() {return !m_filename.empty();}
|
return m_filename.c_str();
|
||||||
|
}
|
||||||
|
const string &getreason()
|
||||||
|
{
|
||||||
|
return m_reason;
|
||||||
|
}
|
||||||
|
void setnoremove(bool onoff)
|
||||||
|
{
|
||||||
|
m_noremove = onoff;
|
||||||
|
}
|
||||||
|
bool ok()
|
||||||
|
{
|
||||||
|
return !m_filename.empty();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
string m_filename;
|
string m_filename;
|
||||||
string m_reason;
|
string m_reason;
|
||||||
|
bool m_noremove;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef RefCntr<TempFileInternal> TempFile;
|
typedef RefCntr<TempFileInternal> TempFile;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user