Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
evd::Temporaries Class Reference

#include <Temporaries.h>

Public Member Functions

 Temporaries ()
 
 ~Temporaries ()
 
std::string DirectoryName () const
 
FILE * fopen (const std::string &fname, const char *mode)
 
std::ofstream ofstream (const std::string &fname)
 
int symlink (const std::string &dir, const std::string &fname)
 
std::string compress (const std::string &fname)
 

Protected Member Functions

void AddCleanup (const std::string &fname)
 

Protected Attributes

std::string fTempDir
 
std::vector< std::stringfCleanup
 
std::mutex fLock
 

Detailed Description

Definition at line 14 of file Temporaries.h.

Constructor & Destructor Documentation

evd::Temporaries::Temporaries ( )

Definition at line 8 of file Temporaries.cxx.

9  {
10  fTempDir = "/tmp/webevd_XXXXXX";
11  mkdtemp(fTempDir.data());
12  }
std::string fTempDir
Definition: Temporaries.h:32
evd::Temporaries::~Temporaries ( )

Definition at line 15 of file Temporaries.cxx.

16  {
17  for(const std::string& f: fCleanup) unlink((fTempDir+"/"+f).c_str());
18 
19  if(rmdir(fTempDir.c_str()) != 0){
20  std::cout << "Failed to clean up temporary directory " << fTempDir << std::endl;
21  }
22  }
std::string string
Definition: nybbler.cc:12
def rmdir(dir, verbose)
Definition: emptydir.py:155
std::string fTempDir
Definition: Temporaries.h:32
std::vector< std::string > fCleanup
Definition: Temporaries.h:33
QTextStream & endl(QTextStream &s)

Member Function Documentation

void evd::Temporaries::AddCleanup ( const std::string fname)
protected

Definition at line 25 of file Temporaries.cxx.

26  {
27  const std::scoped_lock l(fLock);
28  fCleanup.push_back(fname);
29  }
static QStrList * l
Definition: config.cpp:1044
std::mutex fLock
Definition: Temporaries.h:35
std::vector< std::string > fCleanup
Definition: Temporaries.h:33
std::string evd::Temporaries::compress ( const std::string fname)

Definition at line 54 of file Temporaries.cxx.

55  {
56  const std::string tgt = fname+".gz";
57  // Don't destroy original, use fastest compression
58  system(("gzip -c -1 " + fTempDir+"/"+fname+" > " + fTempDir+"/"+tgt).c_str());
59  AddCleanup(tgt);
60  return fTempDir+"/"+tgt;
61  }
std::string string
Definition: nybbler.cc:12
void AddCleanup(const std::string &fname)
Definition: Temporaries.cxx:25
std::string fTempDir
Definition: Temporaries.h:32
std::string evd::Temporaries::DirectoryName ( ) const
inline

Definition at line 20 of file Temporaries.h.

20 {return fTempDir;}
std::string fTempDir
Definition: Temporaries.h:32
FILE * evd::Temporaries::fopen ( const std::string fname,
const char *  mode 
)

Definition at line 32 of file Temporaries.cxx.

33  {
35  return ::fopen((fTempDir+"/"+fname).c_str(), mode);
36  }
void AddCleanup(const std::string &fname)
Definition: Temporaries.cxx:25
std::string fTempDir
Definition: Temporaries.h:32
std::ofstream evd::Temporaries::ofstream ( const std::string fname)

Definition at line 39 of file Temporaries.cxx.

40  {
42  return std::ofstream(fTempDir+"/"+fname);
43  }
void AddCleanup(const std::string &fname)
Definition: Temporaries.cxx:25
std::string fTempDir
Definition: Temporaries.h:32
int evd::Temporaries::symlink ( const std::string dir,
const std::string fname 
)

Definition at line 46 of file Temporaries.cxx.

47  {
49  return ::symlink(TString::Format("%s/%s", dir.c_str(), fname.c_str()).Data(),
50  TString::Format("%s/%s", fTempDir.c_str(), fname.c_str()).Data());
51  }
void AddCleanup(const std::string &fname)
Definition: Temporaries.cxx:25
string dir
def symlink(src, dest)
std::string fTempDir
Definition: Temporaries.h:32
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:146

Member Data Documentation

std::vector<std::string> evd::Temporaries::fCleanup
protected

Definition at line 33 of file Temporaries.h.

std::mutex evd::Temporaries::fLock
protected

Definition at line 35 of file Temporaries.h.

std::string evd::Temporaries::fTempDir
protected

Definition at line 32 of file Temporaries.h.


The documentation for this class was generated from the following files: