Switch to unified view

a/src/utils/circache.cpp b/src/utils/circache.cpp
...
...
439
            m_uniquentries = stringToBool(value);
439
            m_uniquentries = stringToBool(value);
440
        }
440
        }
441
        return true;
441
        return true;
442
    }
442
    }
443
443
444
    bool writeEntryHeader(off_t offset, const EntryHeaderData& d) {
444
    bool writeEntryHeader(off_t offset, const EntryHeaderData& d,
445
                          bool eraseData = false) {
445
        if (m_fd < 0) {
446
        if (m_fd < 0) {
446
            m_reason << "writeEntryHeader: not open ";
447
            m_reason << "writeEntryHeader: not open ";
447
            return false;
448
            return false;
448
        }
449
        }
449
        char bf[CIRCACHE_HEADER_SIZE];
450
        char bf[CIRCACHE_HEADER_SIZE];
...
...
456
            return false;
457
            return false;
457
        }
458
        }
458
        if (write(m_fd, bf, CIRCACHE_HEADER_SIZE) !=  CIRCACHE_HEADER_SIZE) {
459
        if (write(m_fd, bf, CIRCACHE_HEADER_SIZE) !=  CIRCACHE_HEADER_SIZE) {
459
            m_reason << "CirCache::weh: write failed. errno " << errno;
460
            m_reason << "CirCache::weh: write failed. errno " << errno;
460
            return false;
461
            return false;
462
        }
463
        if (eraseData == true) {
464
            if (d.dicsize || d.datasize) {
465
                m_reason << "CirCache::weh: erase requested but not empty";
466
                return false;
467
            }
468
            string buf(d.padsize, ' ');
469
            if (write(m_fd, buf.c_str(), d.padsize) != d.padsize) {
470
                m_reason << "CirCache::weh: write failed. errno " << errno;
471
                return false;
472
            }
461
        }
473
        }
462
        return true;
474
        return true;
463
    }
475
    }
464
476
465
    CCScanHook::status readEntryHeader(off_t offset, EntryHeaderData& d) {
477
    CCScanHook::status readEntryHeader(off_t offset, EntryHeaderData& d) {
...
...
926
    LOGDEB0(("Circache::get: scanfound, %d mS\n", chron.millis()));
938
    LOGDEB0(("Circache::get: scanfound, %d mS\n", chron.millis()));
927
939
928
    return bret;
940
    return bret;
929
}
941
}
930
942
931
bool CirCache::erase(const string& udi)
943
bool CirCache::erase(const string& udi, bool reallyclear)
932
{
944
{
933
    if (m_d == 0) {
945
    if (m_d == 0) {
934
        LOGERR(("CirCache::erase: null data\n"));
946
        LOGERR(("CirCache::erase: null data\n"));
935
        return false;
947
        return false;
936
    }
948
    }
...
...
958
        LOGDEB(("CirCache::erase: khFind returns none\n"));
970
        LOGDEB(("CirCache::erase: khFind returns none\n"));
959
        return true;
971
        return true;
960
    }
972
    }
961
973
962
    for (vector<off_t>::iterator it = ofss.begin(); it != ofss.end(); it++) {
974
    for (vector<off_t>::iterator it = ofss.begin(); it != ofss.end(); it++) {
963
        LOGDEB(("CirCache::erase: reading at %lu\n", (unsigned long)*it));
975
        LOGDEB2(("CirCache::erase: reading at %lu\n", (unsigned long)*it));
964
        EntryHeaderData d;
976
        EntryHeaderData d;
965
        string fudi;
977
        string fudi;
966
        if (!m_d->readHUdi(*it, d, fudi)) {
978
        if (!m_d->readHUdi(*it, d, fudi)) {
967
            return false;
979
            return false;
968
        }
980
        }
969
        LOGDEB(("CirCache::erase: found fudi [%s]\n", fudi.c_str()));
981
        LOGDEB2(("CirCache::erase: found fudi [%s]\n", fudi.c_str()));
970
        if (!fudi.compare(udi)) {
982
        if (!fudi.compare(udi)) {
971
            EntryHeaderData nd;
983
            EntryHeaderData nd;
972
            nd.padsize = d.dicsize + d.datasize + d.padsize;
984
            nd.padsize = d.dicsize + d.datasize + d.padsize;
973
            LOGDEB(("CirCache::erase: rewriting at %lu\n", (unsigned long)*it));
985
            LOGDEB2(("CirCache::erase: rewrite at %lu\n", (unsigned long)*it));
974
            if (*it == m_d->m_nheadoffs) {
986
            if (*it == m_d->m_nheadoffs) {
975
                m_d->m_npadsize = nd.padsize;
987
                m_d->m_npadsize = nd.padsize;
976
            }
988
            }
977
            if (!m_d->writeEntryHeader(*it, nd)) {
989
            if (!m_d->writeEntryHeader(*it, nd, reallyclear)) {
978
                LOGERR(("CirCache::erase: write header failed\n"));
990
                LOGERR(("CirCache::erase: write header failed\n"));
979
                return false;
991
                return false;
980
            }
992
            }
981
        }
993
        }
982
    }
994
    }
...
...
1048
    TempBuf compbuf;
1060
    TempBuf compbuf;
1049
    if (!(iflags & NoCompHint)) {
1061
    if (!(iflags & NoCompHint)) {
1050
        uLong len = compressBound(static_cast<uLong>(data.size()));
1062
        uLong len = compressBound(static_cast<uLong>(data.size()));
1051
        char *bf = compbuf.setsize(len);
1063
        char *bf = compbuf.setsize(len);
1052
        if (bf != 0 &&
1064
        if (bf != 0 &&
1053
                compress((Bytef*)bf, &len, (Bytef*)data.c_str(), static_cast<uLong>(data.size()))
1065
                compress((Bytef*)bf, &len, (Bytef*)data.c_str(),
1054
                == Z_OK) {
1066
                         static_cast<uLong>(data.size())) == Z_OK) {
1055
            if (float(len) < 0.9 * float(data.size())) {
1067
            if (float(len) < 0.9 * float(data.size())) {
1056
                // bf is local but it's our static buffer address
1068
                // bf is local but it's our static buffer address
1057
                datap = bf;
1069
                datap = bf;
1058
                datalen = len;
1070
                datalen = len;
1059
                flags |= EFDataCompressed;
1071
                flags |= EFDataCompressed;