Merge branch 'master' of https://DennisOSRM@github.com/DennisOSRM/Project-OSRM.git
This commit is contained in:
		
						commit
						9c1caba2fa
					
				@ -24,8 +24,8 @@
 | 
			
		||||
 | 
			
		||||
TemporaryStorage::TemporaryStorage() {
 | 
			
		||||
    try {
 | 
			
		||||
        tempDirectory = boost::filesystem3::temp_directory_path();
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
        tempDirectory = boost::filesystem::temp_directory_path();
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        ERR("could not retrieve location of temporary path: " << e.what());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -45,7 +45,7 @@ void TemporaryStorage::removeAll() {
 | 
			
		||||
        for(int slotID = 0; slotID < vectorOfStreamDatas.size(); ++slotID)
 | 
			
		||||
            deallocateSlot(slotID);
 | 
			
		||||
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        ERR("could not retrieve location of temporary path: " << e.what());
 | 
			
		||||
    }
 | 
			
		||||
    vectorOfStreamDatas.clear();
 | 
			
		||||
@ -56,7 +56,7 @@ int TemporaryStorage::allocateSlot() {
 | 
			
		||||
    try {
 | 
			
		||||
        vectorOfStreamDatas.push_back(StreamData());
 | 
			
		||||
        //INFO("created new temporary file: " << vectorOfStreamDatas.back().pathToTemporaryFile);
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        abort(e);
 | 
			
		||||
    }
 | 
			
		||||
    return vectorOfStreamDatas.size() - 1;
 | 
			
		||||
@ -66,15 +66,15 @@ void TemporaryStorage::deallocateSlot(int slotID) {
 | 
			
		||||
    try {
 | 
			
		||||
        StreamData & data = vectorOfStreamDatas[slotID];
 | 
			
		||||
        boost::mutex::scoped_lock lock(*data.readWriteMutex);
 | 
			
		||||
                if(!boost::filesystem3::exists(data.pathToTemporaryFile)) {
 | 
			
		||||
                if(!boost::filesystem::exists(data.pathToTemporaryFile)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if(data.streamToTemporaryFile->is_open())
 | 
			
		||||
            data.streamToTemporaryFile->close();
 | 
			
		||||
 | 
			
		||||
        //INFO("deallocating slot " << slotID << " and its file: " << data.pathToTemporaryFile);
 | 
			
		||||
        boost::filesystem3::remove(data.pathToTemporaryFile);
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
        boost::filesystem::remove(data.pathToTemporaryFile);
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        abort(e);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -86,7 +86,7 @@ void TemporaryStorage::writeToSlot(int slotID, char * pointer, std::streamsize s
 | 
			
		||||
        if(!data.writeMode)
 | 
			
		||||
            ERR("Writing after first read is not allowed");
 | 
			
		||||
        data.streamToTemporaryFile->write(pointer, size);
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        abort(e);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -99,46 +99,46 @@ void TemporaryStorage::readFromSlot(int slotID, char * pointer, std::streamsize
 | 
			
		||||
            data.streamToTemporaryFile->seekg(0, data.streamToTemporaryFile->beg);
 | 
			
		||||
        }
 | 
			
		||||
        data.streamToTemporaryFile->read(pointer, size);
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        abort(e);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned TemporaryStorage::getFreeBytesOnTemporaryDevice() {
 | 
			
		||||
    boost::filesystem3::space_info tempSpaceInfo;
 | 
			
		||||
    boost::filesystem::space_info tempSpaceInfo;
 | 
			
		||||
    try {
 | 
			
		||||
        tempSpaceInfo = boost::filesystem3::space(tempDirectory);
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
        tempSpaceInfo = boost::filesystem::space(tempDirectory);
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        abort(e);
 | 
			
		||||
    }
 | 
			
		||||
    return tempSpaceInfo.available;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
boost::filesystem3::fstream::pos_type TemporaryStorage::tell(int slotID) {
 | 
			
		||||
    boost::filesystem3::fstream::pos_type position;
 | 
			
		||||
boost::filesystem::fstream::pos_type TemporaryStorage::tell(int slotID) {
 | 
			
		||||
    boost::filesystem::fstream::pos_type position;
 | 
			
		||||
    try {
 | 
			
		||||
        StreamData & data = vectorOfStreamDatas[slotID];
 | 
			
		||||
        boost::mutex::scoped_lock lock(*data.readWriteMutex);
 | 
			
		||||
        position = data.streamToTemporaryFile->tellp();
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        abort(e);
 | 
			
		||||
   }
 | 
			
		||||
//    INFO("telling position: " << position);
 | 
			
		||||
    return position;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TemporaryStorage::abort(boost::filesystem3::filesystem_error& e) {
 | 
			
		||||
void TemporaryStorage::abort(boost::filesystem::filesystem_error& e) {
 | 
			
		||||
    removeAll();
 | 
			
		||||
//    ERR("I/O Error occured: " << e.what());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TemporaryStorage::seek(int slotID, boost::filesystem3::fstream::pos_type position) {
 | 
			
		||||
void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type position) {
 | 
			
		||||
    try {
 | 
			
		||||
        StreamData & data = vectorOfStreamDatas[slotID];
 | 
			
		||||
        boost::mutex::scoped_lock lock(*data.readWriteMutex);
 | 
			
		||||
        data.streamToTemporaryFile->seekg(position);
 | 
			
		||||
//        INFO("seeking to position: " << position);
 | 
			
		||||
    } catch(boost::filesystem3::filesystem_error & e) {
 | 
			
		||||
    } catch(boost::filesystem::filesystem_error & e) {
 | 
			
		||||
        abort(e);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -31,6 +31,31 @@
 | 
			
		||||
 | 
			
		||||
#include "../typedefs.h"
 | 
			
		||||
 | 
			
		||||
//This is one big workaround for latest boost renaming woes.
 | 
			
		||||
 | 
			
		||||
#ifndef BOOST_FILESYSTEM_VERSION
 | 
			
		||||
#warning Boost Installation with Filesystem3 (>=1.44) is required, activating workaround
 | 
			
		||||
#include <cstdio>
 | 
			
		||||
namespace boost {
 | 
			
		||||
namespace filesystem {
 | 
			
		||||
inline path temp_directory_path() {
 | 
			
		||||
	char * buffer;
 | 
			
		||||
	buffer = tmpnam (NULL);
 | 
			
		||||
 | 
			
		||||
	return path(buffer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline path unique_path(const path&) {
 | 
			
		||||
	return temp_directory_path();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define BOOST_FILESYSTEM_VERSION 3
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class implements a singleton file storage for temporary data.
 | 
			
		||||
 * temporary slots can be accessed by other objects through an int
 | 
			
		||||
@ -39,7 +64,8 @@
 | 
			
		||||
 * Access is sequential, which means, that there is no random access
 | 
			
		||||
 * -> Data is written in first phase and reread in second.
 | 
			
		||||
 */
 | 
			
		||||
static boost::filesystem3::path tempDirectory;
 | 
			
		||||
 | 
			
		||||
static boost::filesystem::path tempDirectory;
 | 
			
		||||
static std::string TemporaryFilePattern("OSRM-%%%%-%%%%-%%%%");
 | 
			
		||||
class TemporaryStorage {
 | 
			
		||||
public:
 | 
			
		||||
@ -52,8 +78,8 @@ public:
 | 
			
		||||
    void readFromSlot(int slotID, char * pointer, std::streamsize size);
 | 
			
		||||
    //returns the number of free bytes
 | 
			
		||||
    unsigned getFreeBytesOnTemporaryDevice();
 | 
			
		||||
    boost::filesystem3::fstream::pos_type tell(int slotID);
 | 
			
		||||
    void seek(int slotID, boost::filesystem3::fstream::pos_type);
 | 
			
		||||
    boost::filesystem::fstream::pos_type tell(int slotID);
 | 
			
		||||
    void seek(int slotID, boost::filesystem::fstream::pos_type);
 | 
			
		||||
    void removeAll();
 | 
			
		||||
private:
 | 
			
		||||
    TemporaryStorage();
 | 
			
		||||
@ -61,19 +87,19 @@ private:
 | 
			
		||||
    TemporaryStorage& operator=(TemporaryStorage const &) {
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
    void abort(boost::filesystem3::filesystem_error& e);
 | 
			
		||||
    void abort(boost::filesystem::filesystem_error& e);
 | 
			
		||||
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
    struct StreamData {
 | 
			
		||||
        bool writeMode;
 | 
			
		||||
        boost::filesystem3::path pathToTemporaryFile;
 | 
			
		||||
        boost::shared_ptr<boost::filesystem3::fstream> streamToTemporaryFile;
 | 
			
		||||
        boost::filesystem::path pathToTemporaryFile;
 | 
			
		||||
        boost::shared_ptr<boost::filesystem::fstream> streamToTemporaryFile;
 | 
			
		||||
        boost::shared_ptr<boost::mutex> readWriteMutex;
 | 
			
		||||
        StreamData() :
 | 
			
		||||
            writeMode(true),
 | 
			
		||||
            pathToTemporaryFile (boost::filesystem3::unique_path(tempDirectory.append(TemporaryFilePattern.begin(), TemporaryFilePattern.end()))),
 | 
			
		||||
            streamToTemporaryFile(new boost::filesystem3::fstream(pathToTemporaryFile, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)),
 | 
			
		||||
            pathToTemporaryFile (boost::filesystem::unique_path(tempDirectory.append(TemporaryFilePattern.begin(), TemporaryFilePattern.end()))),
 | 
			
		||||
            streamToTemporaryFile(new boost::filesystem::fstream(pathToTemporaryFile, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)),
 | 
			
		||||
            readWriteMutex(new boost::mutex)
 | 
			
		||||
        {
 | 
			
		||||
            if(streamToTemporaryFile->fail())
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user