#include <iostream>
#include <time.h>
#include <dirent.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/stream.hpp>
{
*readnewconfig = false;
- if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return;
+ if( DATADIR == "" || !(MODE==CACHE_MODE_RO||MODE==CACHE_MODE_RW) ) return;
if(refetchDataFiles){
refetchDataFiles = false;
void configcache::openOutFile(int actnequi)
{
time_t secstamp = time(NULL);
+ int iseq=0;
+
+ while (true) {
+ outFileName.str("");
+ outFileName << DATADIR << "/" << secstamp << "." << iseq << "_" << getFileId(actnequi) << "_.edat.tmp";
+
+ int tmpfd = open(outFileName.str().c_str(), O_CREAT | O_EXCL, 0644);
- outFileName.str("");
- outFileName << DATADIR << "/" << secstamp << "_" << getFileId(actnequi) << "_.edat.tmp";
+ if ( tmpfd != -1 ) {
+ close(tmpfd);
+ break;
+ }
+ else if ( errno != EEXIST ) {
+ if(log) *log << "CCACHE: Could not create cachefile!" << endl << flush;
+ exit(1);
+ }
+ iseq++;
+ }
+
outFile.open( outFileName.str().c_str(), std::ios::binary );
ioBuffers->out = new boost::iostreams::filtering_ostreambuf;
void configcache::writeHeader(const string& headerid, const char *header, long unsigned int size, int actnequi) {
unsigned long headeridhash;
- if( DATADIR == "" || MODE < 2 ) return;
+ if( DATADIR == "" || !(MODE==CACHE_MODE_WO||MODE==CACHE_MODE_RW) ) return;
if(!outFile.is_open())
openOutFile(actnequi);
{
long unsigned int zeroheader=0;
- if ( DATADIR == "" || MODE < 2 ) return;
+ if ( DATADIR == "" || !(MODE==CACHE_MODE_WO||MODE==CACHE_MODE_RW) ) return;
if ( ! outFile.is_open() )
openOutFile(actnequi);