Example #1
0
bool Cache::store() {
    if(!initialized_)
        return false;

    std::string dir = getCurrentCacheDir();
    if (!FileSys.dirExists(dir)) {
        if(!FileSys.createDirectoryRecursive(dir))
            return false;

        //write property state:
        std::string propertyState = getPropertyState();
        std::string fname = dir + "/propertystate.txt";

        std::fstream out(fname.c_str(), std::ios::out | std::ios::binary);

        if (out.is_open() || !out.bad()) {
            out.write(propertyState.c_str(), propertyState.length());
        }
        else {
            LERROR("Could not write propertystate file!");
            FileSys.deleteDirectoryRecursive(dir);
            return false;
        }

        out.close();

        return storeOutportsToDir(dir);
    }
    else {
        std::string fname = dir + "/propertystate.txt";

        if(FileSys.fileExists(fname)) {
            std::string propertyState = getPropertyState();
            if(stringEqualsFileContent(propertyState, fname))
                return true;
            else {
                LWARNING("PropertyState Collision! Deleting cache entry.");
                FileSys.deleteDirectoryRecursive(dir);
                return storeOutportsToDir(dir);
            }
        }
        else {
            LWARNING("No PropertyState in cache entry! Deleting.");
            FileSys.deleteDirectoryRecursive(dir);
            return storeOutportsToDir(dir);
        }
    }
}
Example #2
0
bool Cache::writePropertyState(std::string dir) {
    //write property state:
    std::string propertyState = getPropertyState();
    std::string fname = dir + "/propertystate.txt";

    std::fstream out(fname.c_str(), std::ios::out | std::ios::binary);

    if (out.is_open() || !out.bad())
        out.write(propertyState.c_str(), propertyState.length());
    else
        return false;

    out.close();

    return true;
}
Example #3
0
bool Cache::restore() {
    if(!initialized_)
        return false;

    //check for collisions
    std::string dir = getCurrentCacheDir();
    if(FileSys.dirExists(dir)) {
        std::string fname = dir + "/propertystate.txt";

        if(!FileSys.fileExists(fname))
            return false;

        std::string propertyState = getPropertyState();
        if(stringEqualsFileContent(propertyState, fname))
            return restoreOutportsFromDir(dir);
        else {
            LWARNING("PropertyState Collision! Deleting cache entry.");
            FileSys.deleteDirectoryRecursive(dir);
            return false;
        }
    }
    else
        return false;
}
Example #4
0
std::string Cache::getPropertyStateHash() {
    return VoreenHash::getHash(getPropertyState());
}