Beispiel #1
0
void CGBRequestStatistics::PrintStat(void) const
{
    size_t count = GetCount();
    if ( count > 0 ) {
        double time = GetTime();
        double size = GetSize();
        if ( size <= 0 ) {
            LOG_POST_X(5, "GBLoader: " << GetAction() << ' ' <<
                       count << ' ' << GetEntity() << " in " <<
                       setiosflags(ios::fixed) <<
                       setprecision(3) <<
                       (time) << " s (" <<
                       (time*1000/count) << " ms/one)");
        }
        else {
            LOG_POST_X(6, "GBLoader: " << GetAction() << ' ' <<
                       count << ' ' << GetEntity() << " in " <<
                       setiosflags(ios::fixed) <<
                       setprecision(3) <<
                       (time) << " s (" <<
                       (time*1000/count) << " ms/one)" <<
                       setprecision(2) << " (" <<
                       (size/1024.0) << " kB " <<
                       (size/time/1024) << " kB/s)");
        }
    }
}
Beispiel #2
0
void CBDB_Env::StopBackgroundWriterThread()
{
# ifdef NCBI_THREADS
    if (!m_CheckThread.Empty()) {
        LOG_POST_X(8, Info << "Stopping BDB transaction checkpoint thread...");
        m_CheckThread->RequestStop();
        m_CheckThread->Join();
        LOG_POST_X(9, Info << "BDB transaction checkpoint thread stopped.");
    }
# endif
}
Beispiel #3
0
void CLDS_File::UpdateEntry(int    file_id,
                            const  string& file_name,
                            Uint4  crc,
                            int    time_stamp,
                            Int8   file_size,
                            bool   compute_check_sum)
{
    if (!crc && compute_check_sum) {
        crc = ComputeFileCRC32(file_name);
    }

    m_FileDB.file_id = file_id;
    if (m_FileDB.Fetch() != eBDB_Ok) {
        LDS_THROW(eRecordNotFound, "Files record not found");
    }

    // Re-evalute the file format

    CFormatGuess fg;
    CFormatGuess::EFormat format = fg.Format(file_name);

    m_FileDB.format = format;
    m_FileDB.time_stamp = time_stamp;
    m_FileDB.CRC = crc;
    m_FileDB.file_size = file_size;

    EBDB_ErrCode err = m_FileDB.UpdateInsert();
    BDB_CHECK(err, "LDS::File");

    LOG_POST_X(5, Info << "LDS: file update: " << file_name);

}
Beispiel #4
0
void CBDB_Env::RunBackgroundWriter(TBackgroundFlags flags,
                                   unsigned thread_delay,
                                   int memp_trickle,
                                   unsigned err_max)
{
# ifdef NCBI_THREADS
    LOG_POST_X(6, Info << "Starting BDB transaction checkpoint thread.");
    m_CheckThread.Reset(
        new CBDB_CheckPointThread(*this, memp_trickle, thread_delay, 5));
    m_CheckThread->SetMaxErrors(err_max);
    m_CheckThread->SetWorkFlag(flags);
    m_CheckThread->Run();
# else
    LOG_POST_X(7, Warning <<
     "Cannot run BDB transaction checkpoint thread in non-MT configuration.");
# endif
}
Beispiel #5
0
void CLDS2_Database::DeleteFile(const string& file_name)
{
    LOG_POST_X(4, Info << "LDS2: Deleting file " << file_name);
    CSQLITE_Statement& st = x_GetStatement(eSt_DeleteFileByName);
    st.Bind(1, file_name);
    st.Execute();
    st.Reset();
}
Beispiel #6
0
void CLDS2_Database::DeleteFile(Int8 file_id)
{
    LOG_POST_X(4, Info << "LDS2: Deleting file " << file_id);
    CSQLITE_Statement& st = x_GetStatement(eSt_DeleteFileById);
    st.Bind(1, file_id);
    st.Execute();
    st.Reset();
}
Beispiel #7
0
void CLDS_File::SyncWithDir(const string& path,
                            CLDS_Set*     deleted,
                            CLDS_Set*     updated,
                            TFlags        flags)
{
    CDir dir(path);
    if (!dir.Exists()) {
        string err("Directory is not found or access denied:");
        err.append(path);

        LDS_THROW(eFileNotFound, err);
    }

    set<string> files;

    // Scan the directory, compare it against File table

    x_SyncWithDir(path,
                  deleted,
                  updated,
                  &files,
                  flags);

    // Scan the database, find deleted files

    bool keep_other_files =
        (flags & CLDS_Manager::fOtherFilesMask) == CLDS_Manager::fKeepOtherFiles;
    CBDB_FileCursor cur(m_FileDB);
    cur.SetCondition(CBDB_FileCursor::eFirst);
    while (cur.Fetch() == eBDB_Ok) {
        string fname(m_FileDB.file_name);
        set<string>::const_iterator fit = files.find(fname);
        if (fit == files.end()) { // not found
            if ( keep_other_files && !NStr::StartsWith(fname, path) ) {
                LOG_POST_X(1, Info << "LDS: Keeping other: " << fname);
                continue;
            }
            deleted->set(m_FileDB.file_id);

            LOG_POST_X(1, Info << "LDS: File removed: " << fname);
        }
    } // while

    Delete(*deleted);
}
Beispiel #8
0
static
rc_t VDBLogWriter(void* data, const char* buffer, size_t size, size_t* written)
{
    CTempString msg(buffer, size);
    NStr::TruncateSpacesInPlace(msg);
    LOG_POST_X(2, "VDB: "<<msg);
    *written = size;
    return 0;
}
Beispiel #9
0
int CBDB_Env::x_Open(const char* db_home, int flags)
{
    int recover_requested = flags & DB_RECOVER;

    int ret = m_Env->open(m_Env, db_home, flags, 0664);
    if (ret == DB_RUNRECOVERY) {
        if (flags & DB_JOINENV) {  // join do not attempt recovery
            return ret;
        }
        int recover_flag;

        if (!recover_requested) {
            if (flags & DB_INIT_TXN) { // recovery needs transaction
                recover_flag = flags | DB_RECOVER | DB_CREATE;
            } else {
                goto fatal_recovery;
            }
        } else {
            goto fatal_recovery;
        }

        ret = m_Env->open(m_Env, db_home, recover_flag, 0664);

        if (!recover_requested) {
            fatal_recovery:
            LOG_POST_X(1, Warning << "BDB_Env: Trying fatal recovery.");
            if ((ret == DB_RUNRECOVERY) && (flags & DB_INIT_TXN)) {
                recover_flag &= ~DB_RECOVER;
                recover_flag = flags | DB_RECOVER_FATAL | DB_CREATE;

                ret = m_Env->open(m_Env, db_home, recover_flag, 0664);
                if (ret) {
                    LOG_POST_X(2, Warning <<
                               "Fatal recovery returned error code=" << ret);
                }
            }
        }
    }
    m_HomePath = db_home;
    return ret;
}
Beispiel #10
0
//
// initialize PNG writing
//
static void s_PngWriteInit(png_structp& png_ptr,
                           png_infop&   info_ptr,
                           size_t width, size_t height, size_t depth,
                           CImageIO::ECompress compress)
{
    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
                                      s_PngWriteErrorHandler,
                                      s_PngWarningHandler);
    if ( !png_ptr ) {
        NCBI_THROW(CImageException, eWriteError,
                   "CImageIOPng::WriteImage(): png_create_read_struct() failed");
    }

    info_ptr = png_create_info_struct(png_ptr);
    if ( !info_ptr ) {
        NCBI_THROW(CImageException, eWriteError,
                   "CImageIOPng::WriteImage(): png_create_info_struct() failed");
    }

    png_byte color_type = PNG_COLOR_TYPE_RGB;
    if (depth == 4) {
        color_type = PNG_COLOR_TYPE_RGBA;
    }
    png_set_IHDR(png_ptr, info_ptr,
                 width, height, 8, color_type,
                 PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_BASE,
                 PNG_FILTER_TYPE_BASE);

    // set our compression quality
    switch (compress) {
    case CImageIO::eCompress_None:
        png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
        png_set_compression_level(png_ptr, Z_NO_COMPRESSION);
        break;
    case CImageIO::eCompress_Low:
        png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
        png_set_compression_level(png_ptr, Z_BEST_SPEED);
        break;
    case CImageIO::eCompress_Medium:
        png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
        break;
    case CImageIO::eCompress_High:
        png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
        break;
    default:
        LOG_POST_X(26, Error << "unknown compression type: " << (int)compress);
        break;
    }

}
Beispiel #11
0
void CLDS2_Database::AddFile(SLDS2_File& info)
{
    LOG_POST_X(2, Info << "LDS2: Adding file " << info.name);
    CSQLITE_Statement& st = x_GetStatement(eSt_AddFile);
    st.Bind(1, info.name);
    st.Bind(2, info.format);
    st.Bind(3, info.handler);
    st.Bind(4, info.size);
    st.Bind(5, info.time);
    st.Bind(6, info.crc);
    st.Execute();
    info.id = st.GetLastInsertedRowid();
    st.Reset();
}
Beispiel #12
0
static void ALIGNMENT_CALLBACK s_ReportError(TErrorInfoPtr err_ptr,
                                             void *user_data)
{
    CAlnReader::TErrorList *err_list;
    TErrorInfoPtr           next_err;
    
    while (err_ptr != NULL) {    
        if (user_data != NULL) {
            err_list = (CAlnReader::TErrorList *)user_data;
            (*err_list).push_back (CAlnError(err_ptr->category, err_ptr->line_num, 
                                             err_ptr->id == NULL ? "" : err_ptr->id, 
                                             err_ptr->message == NULL ? "" : err_ptr->message));
        }
        
        string msg = "Error reading alignment file";
        if (err_ptr->line_num > -1) {
            msg += " at line " + NStr::IntToString(err_ptr->line_num);
        }
        if (err_ptr->message) {
            msg += ":  ";
            msg += err_ptr->message;
        }

        if (err_ptr->category == eAlnErr_Fatal) {
            LOG_POST_X(1, Error << msg);
        } else {
            LOG_POST_X(1, Info << msg);
        }

        next_err = err_ptr->next;  
        free (err_ptr->id);
        free (err_ptr->message);
        free (err_ptr);
        err_ptr = next_err;
    }
}
Beispiel #13
0
void CLDS2_Database::Create(void)
{
    LOG_POST_X(1, Info << "LDS2: Creating database " <<  m_DbFile);

    // Close the connection if any
    x_ResetDbConnection();

    // Delete all data
    CFile dbf(m_DbFile);
    if ( dbf.Exists() ) {
        dbf.Remove();
    }

    // Initialize connection and create tables:
    x_ExecuteSqls(kLDS2_CreateDB,
        sizeof(kLDS2_CreateDB)/sizeof(kLDS2_CreateDB[0]));
}
Beispiel #14
0
void CBDB_Env::CleanLog()
{
    char **nm_list = 0;
    int ret =
        m_Env->log_archive(m_Env, &nm_list, DB_ARCH_ABS);
    BDB_CHECK(ret, "DB_ENV::CleanLog()");

    if (nm_list != NULL) {
        for (char** file = nm_list; *file != NULL; ++file) {
            LOG_POST_X(5, Info << "BDB_Env: Removing LOG file: " << *file);
            CDirEntry de(*file);
            de.Remove();
        }
        free(nm_list);
    }

}
Beispiel #15
0
void CId2Reader::x_DisconnectAtSlot(TConn conn, bool failed)
{
    _ASSERT(m_Connections.count(conn));
    CReaderServiceConnector::SConnInfo& conn_info = m_Connections[conn];
    m_Connector.RememberIfBad(conn_info);
    if ( conn_info.m_Stream ) {
        LOG_POST_X(1, Warning << "CId2Reader("<<conn<<"): ID2"
                   " GenBank connection "<<(failed? "failed": "too old")<<
                   ": reconnecting...");
        if ( GetDebugLevel() >= eTraceOpen ) {
            CDebugPrinter s(conn, "CId2Reader");
            s << "Closing ID2 connection";
        }
        conn_info.m_Stream.reset();
        if ( GetDebugLevel() >= eTraceOpen ) {
            CDebugPrinter s(conn, "CId2Reader");
            s << "Closed ID2 connection";
        }
    }
}
void CFastaDeflineReader::x_PostWarning(ILineErrorListener* pMessageListener, 
    const TSeqPos lineNumber,
    const string& errMessage, 
    const CObjReaderParseException::EErrCode errCode) 
{
    unique_ptr<CObjReaderLineException> pLineExpt(
        CObjReaderLineException::Create(
        eDiag_Warning,
        lineNumber,
        errMessage, 
        ILineError::eProblem_GeneralParsingError,
        "", "", "", "",
        errCode));

    if (!pMessageListener) {
        LOG_POST_X(1, Warning << pLineExpt->Message());
        return;
    }

    if (!pMessageListener->PutError(*pLineExpt)) {
        throw CObjReaderParseException(DIAG_COMPILE_INFO, 0, errCode, errMessage, lineNumber, eDiag_Warning);
    }
}
Beispiel #17
0
ICache* CDBAPI_BlobCacheCF::CreateInstance(
           const string&                  driver,
           CVersionInfo                   version,
           const TPluginManagerParamTree* params) const
{
    auto_ptr<CDBAPI_Cache> drv;
    if (driver.empty() || driver == m_DriverName) {
        if (version.Match(NCBI_INTERFACE_VERSION(ICache))
                            != CVersionInfo::eNonCompatible) {
            drv.reset(new CDBAPI_Cache());
        }
    } else {
        return 0;
    }

    if (!params)
        return drv.release();

    const string& tree_id = params->GetKey();
    if (NStr::CompareNocase(tree_id, kDBAPI_BlobCacheDriverName) != 0) {
        LOG_POST_X(2, Warning
          << "ICache class factory: Top level Id does not match driver name."
          << " Id = " << tree_id << " driver=" << kDBAPI_BlobCacheDriverName
          << " parameters ignored." );

        return drv.release();
    }

    // cache configuration

    const string& conn_str =
        GetParam(params, kCFParam_connection, false);

    const string& temp_dir =
        GetParam(params, kCFParam_temp_dir, false);
    const string& temp_prefix =
        GetParam(params, kCFParam_temp_prefix, false);

    if (!conn_str.empty()) {
        const void* ptr = NStr::StringToPtr(conn_str);
        IConnection* conn = (IConnection*)ptr;
        drv->Open(conn, temp_dir, temp_prefix);
    } else {
        const string& drv_str =
            GetParam(params, kCFParam_driver, true);
        const string& server =
            GetParam(params, kCFParam_server, true);
        const string& database =
            GetParam(params, kCFParam_database, true);

        string login =
            GetParam(params, kCFParam_login, false, kCFParam_login_default);
        string password =
            GetParam(params,
                     kCFParam_password, false, kCFParam_password_default);

        drv->Open(drv_str, server, database,
                  login, password,
                  temp_dir, temp_prefix);

    }

    const string& mem_size_str =
        GetParam(params, kCFParam_mem_size, false, "0");
    unsigned mem_size = 0;
    
    try {
        mem_size = NStr::StringToUInt(mem_size_str);
    } catch(const CStringException&) {
        // ignore
    }
    if (mem_size) {
        drv->SetMemBufferSize(mem_size);
    }

    return drv.release();
}
Beispiel #18
0
void CLDS2_Database::UpdateFile(SLDS2_File& info)
{
    LOG_POST_X(3, Info << "LDS2: Updating file " << info.name);
    DeleteFile(info.id);
    AddFile(info);
}
Beispiel #19
0
void CWNJobWatcher::Notify(const CWorkerNodeJobContext& job_context,
                            EEvent event)
{
    switch (event) {
    case eJobStarted:
        {
            CMutexGuard guard(m_ActiveJobsMutex);
            m_ActiveJobs[const_cast<CWorkerNodeJobContext*>(&job_context)] =
                    SJobActivity();
            ++m_JobsStarted;
            if (m_MaxJobsAllowed > 0 && m_JobsStarted > m_MaxJobsAllowed - 1) {
                LOG_POST_X(1, "The maximum number of allowed jobs (" <<
                              m_MaxJobsAllowed << ") has been reached. "
                              "Sending the shutdown request." );
                CGridGlobals::GetInstance().
                    RequestShutdown(CNetScheduleAdmin::eNormalShutdown);
            }
        }
        break;
    case eJobStopped:
        {
            CMutexGuard guard(m_ActiveJobsMutex);
            m_ActiveJobs.erase(
                    const_cast<CWorkerNodeJobContext*>(&job_context));
        }
        break;
    case eJobFailed:
        ++m_JobsFailed;
        if (m_MaxFailuresAllowed > 0 &&
                m_JobsFailed > m_MaxFailuresAllowed - 1) {
            LOG_POST_X(2, "The maximum number of failed jobs (" <<
                          m_MaxFailuresAllowed << ") has been reached. "
                          "Shutting down..." );
            CGridGlobals::GetInstance().
                RequestShutdown(CNetScheduleAdmin::eShutdownImmediate);
        }
        break;
    case eJobSucceeded:
        ++m_JobsSucceeded;
        break;
    case eJobReturned:
        ++m_JobsReturned;
        break;
    case eJobRescheduled:
        ++m_JobsRescheduled;
        break;
    case eJobCanceled:
        ++m_JobsCanceled;
        break;
    case eJobLost:
        ++m_JobsLost;
        break;
    }

    if (event != eJobStarted) {
        CGridWorkerNode worker_node(job_context.GetWorkerNode());
        Uint8 total_memory_limit = worker_node.GetTotalMemoryLimit();
        if (total_memory_limit > 0) {  // memory check requested
            size_t memory_usage;
            if (!GetMemoryUsage(&memory_usage, 0, 0)) {
                ERR_POST("Could not check self memory usage" );
            } else if (memory_usage > total_memory_limit) {
                ERR_POST(Warning << "Memory usage (" << memory_usage <<
                    ") is above the configured limit (" <<
                    total_memory_limit << ")");

                CGridGlobals::GetInstance().RequestShutdown(
                    CNetScheduleAdmin::eNormalShutdown,
                        RESOURCE_OVERUSE_EXIT_CODE);
            }
        }

        int total_time_limit = worker_node.GetTotalTimeLimit();
        if (total_time_limit > 0 &&  // time check requested
                time(0) > worker_node.GetStartupTime() + total_time_limit)
            CGridGlobals::GetInstance().RequestShutdown(
                CNetScheduleAdmin::eNormalShutdown, RESOURCE_OVERUSE_EXIT_CODE);
    }
}
Beispiel #20
0
void CObjectsSniffer::ProbeText(CObjectIStream& input)
{
    TCandidates::const_iterator last_cand = m_Candidates.end();

    string format_name;  // for LOG_POST messages
    if (input.GetDataFormat() == eSerial_AsnText) {
        format_name = "ASN.1 text";
    } else {
        format_name = "XML";
    }

    try {
        while (true) {
            m_StreamPos = input.GetStreamPos();
            string header = input.ReadFileHeader();

            if ( last_cand != m_Candidates.end() ) {
                // Check the previously found candidate first
                // (performance optimization)
                if (header == last_cand->type_info.GetTypeInfo()->GetName()) {
                    TCandidates::const_iterator it = last_cand;
                    CObjectInfo object_info(it->type_info.GetTypeInfo());
                    input.Read(object_info, CObjectIStream::eNoFileHeader);
                    m_TopLevelMap.push_back(
                        SObjectDescription(it->type_info, m_StreamPos));

                    _TRACE("Same type "
                           << format_name << " top level object found:" 
                           << it->type_info.GetTypeInfo()->GetName());
                    continue;
                }
            }

            bool found = false;
            // Scan through all candidates
            ITERATE ( TCandidates, it, m_Candidates ) {
                if ( header == it->type_info.GetTypeInfo()->GetName() ) {
                    CObjectInfo object_info(it->type_info.GetTypeInfo());
                    input.Read(object_info, CObjectIStream::eNoFileHeader);
                    found = true;
                    last_cand = it;
                    m_TopLevelMap.push_back(
                        SObjectDescription(it->type_info, m_StreamPos));

                    LOG_POST_X(2, Info 
                                << format_name << " top level object found:" 
                                << it->type_info.GetTypeInfo()->GetName());
                    break;
                }
            } // for
            if ( !found ) {
                input.SetStreamPos(m_StreamPos);
                return;
            }
        } // while
    }
    catch (CEofException& /*ignored*/) {
    }
    catch (exception& e) {
        LOG_POST_X(3, Info << "Exception reading "
                   << format_name << " " << e.what());
        input.SetStreamPos(m_StreamPos);
    }
}
Beispiel #21
0
//
// internal handler: translate PNG warnings to NCBI warnings
//
static void s_PngWarningHandler(png_structp /*png_ptr*/, png_const_charp msg)
{
    LOG_POST_X(25, Warning << "Warning in PNG file: " << msg);
}
Beispiel #22
0
//
// validate our input
//
static void s_PngReadValidate(png_structp png_ptr,
                              png_infop info_ptr,
                              size_t& width,
                              size_t& height,
                              size_t& depth,
                              size_t& x, size_t& y, size_t& w, size_t& h)
{
    // store and validate our image's parameters
    width        = png_get_image_width(png_ptr, info_ptr);
    height       = png_get_image_height(png_ptr, info_ptr);
    depth        = png_get_channels(png_ptr, info_ptr);
    png_byte color_type = png_get_color_type(png_ptr, info_ptr);
    png_byte bit_depth  = png_get_bit_depth(png_ptr, info_ptr);

    // we support only RGB and RGBA images
    if ( color_type != PNG_COLOR_TYPE_RGB  &&
         color_type != PNG_COLOR_TYPE_RGB_ALPHA ) {
        string msg("CImageIOPng::ReadImage(): unhandled color type: ");
        msg += NStr::NumericToString((int)color_type);
        NCBI_THROW(CImageException, eReadError, msg);
    }

    // ...and only with a bit depth of 8
    if (bit_depth != 8) {
        string msg("CImageIOPng::ReadImage(): unhandled bit depth: ");
        msg += NStr::NumericToString((int)bit_depth);
        NCBI_THROW(CImageException, eReadError, msg);
    }

    // this goes along with RGB or RGBA
    if (depth != 3  &&  depth != 4) {
        string msg("CImageIOPng::ReadImage(): unhandled image channels: ");
        msg += NStr::NumericToString((int)depth);
        NCBI_THROW(CImageException, eReadError, msg);
    }

    if (x != (size_t)-1  &&  y != (size_t)-1  &&
        w != (size_t)-1  &&  h != (size_t)-1) {
        // further validation: make sure we're actually on the image
        if (x >= width  ||  y >= height) {
            string msg("CImageIOPng::ReadImage(): invalid starting position: ");
            msg += NStr::NumericToString(x);
            msg += ", ";
            msg += NStr::NumericToString(y);
            NCBI_THROW(CImageException, eReadError, msg);
        }

        // clamp our width and height to the image size
        if (x + w >= width) {
            w = width - x;
            LOG_POST_X(27, Warning
                     << "CImageIOPng::ReadImage(): clamped width to " << w);
        }

        if (y + h >= height) {
            h = height - y;
            LOG_POST_X(28, Warning
                     << "CImageIOPng::ReadImage(): clamped height to " << h);
        }
    }

    png_read_update_info(png_ptr, info_ptr);
}
Beispiel #23
0
void CObjectsSniffer::ProbeASN1_Bin(CObjectIStream& input)
{
    TCandidates::const_iterator last_cand = m_Candidates.end();
    for ( ;; ) {
        m_StreamPos = input.GetStreamPos();

        if ( last_cand != m_Candidates.end() ) {
            // Check the previously found candidate first
            // (performance optimization)
            try {
                TCandidates::const_iterator it = last_cand;
                CObjectInfo object_info(it->type_info.GetTypeInfo());
                input.Read(object_info);
                m_TopLevelMap.push_back(
                    SObjectDescription(it->type_info, m_StreamPos));
                _TRACE("Same type ASN.1 binary top level object found:" 
                       << it->type_info.GetTypeInfo()->GetName());
                continue;
            }
            catch ( CEofException& ) {
                // no more objects
                return;
            }
            catch ( exception& ) {
                Reset();
                input.SetStreamPos(m_StreamPos);
            }
        }

        bool found = false;
        // Scan through all candidates
        ITERATE ( TCandidates, it, m_Candidates ) {
            if ( it == last_cand ) {
                // already tried
                continue;
            }
            try {
                CObjectInfo object_info(it->type_info.GetTypeInfo());
                input.Read(object_info);
                found = true;
                last_cand = it;
                m_TopLevelMap.push_back(
                    SObjectDescription(it->type_info, m_StreamPos));
                LOG_POST_X(2, Info 
                           << "ASN.1 binary top level object found:" 
                           << it->type_info.GetTypeInfo()->GetName());
                break;
            }
            catch ( CEofException& ) {
                // no more objects
                return;
            }
            catch ( exception& ) {
                Reset();
                input.SetStreamPos(m_StreamPos);
            }
        }
        if ( !found ) {
            // no matching candidate
            break;
        }
    } // while
}
Beispiel #24
0
void CLDS_File::x_SyncWithDir(const string& path,
                              CLDS_Set*     deleted,
                              CLDS_Set*     updated,
                              set<string>*  scanned_files,
                              TFlags        flags)
{
    CDir dir(path);
    if (!dir.Exists()) {
        LOG_POST_X(2, Info << "LDS: Directory is not found or access denied:" << path);
        return;
    } else {
        LOG_POST_X(3, Info << "LDS: scanning " << path);
    }

    CLDS_Query lds_query(m_DataBase);
    CChecksum checksum(CChecksum::eCRC32);


    // Scan the directory, compare it against File table
    // Here I intentionally take only files, skipping sub-directories,
    // Second pass scans for sub-dirs and implements recursion

    bool compute_check_sum =
        (flags & CLDS_Manager::fControlSumMask) == CLDS_Manager::fComputeControlSum;

    {{

    CDir::TEntries  content(dir.GetEntries());
    ITERATE(CDir::TEntries, i, content) {
        if (!(*i)->IsFile()) {
            continue;
        }
        (*i)->DereferenceLink();

        CTime modification;
        string entry = (*i)->GetPath();
        string name = (*i)->GetName();
        string ext = (*i)->GetExt();
        (*i)->GetTime(&modification);
        time_t tm = modification.GetTimeT();
        CFile aFile(entry);
        Int8 file_size = aFile.GetLength();

        if (ext == ".db" || ext == ".idx") {
            continue; // Berkeley DB file, no need to index it.
        }

        bool found = lds_query.FindFile(entry);

        scanned_files->insert(entry);

        if (!found) {  // new file arrived
            CFormatGuess fg;

            Uint4 crc = 0;

            if (compute_check_sum) {
                checksum.Reset();
                ComputeFileChecksum(entry, checksum);
                crc = checksum.GetChecksum();
            }

            CFormatGuess::EFormat format = fg.Format(entry);

            FindMaxRecId();
            ++m_MaxRecId;

            m_FileDB.file_id = m_MaxRecId;
            m_FileDB.file_name = entry.c_str();
            m_FileDB.format = format;
            m_FileDB.time_stamp = tm;
            m_FileDB.CRC = crc;
            m_FileDB.file_size = file_size;

            m_FileDB.Insert();

            m_DataBase.GetTables().file_filename_idx.file_id = m_MaxRecId;
            m_DataBase.GetTables().file_filename_idx.file_name = entry.c_str();
            m_DataBase.GetTables().file_filename_idx.UpdateInsert();

            updated->set(m_MaxRecId);

            LOG_POST_X(4, Info << "New LDS file found: " << entry);

            continue;
        }

        if (tm != m_FileDB.time_stamp || file_size != m_FileDB.file_size) {
            updated->set(m_FileDB.file_id);
            UpdateEntry(m_FileDB.file_id,
                        entry,
                        0,
                        tm,
                        file_size,
                        compute_check_sum);
        } else {

            Uint4 crc = 0;
            if (compute_check_sum) {
                checksum.Reset();
                ComputeFileChecksum(entry, checksum);
                crc = checksum.GetChecksum();

                if (crc != (Uint4)m_FileDB.CRC) {
                    updated->set(m_FileDB.file_id);
                    UpdateEntry(m_FileDB.file_id,
                                entry,
                                crc,
                                tm,
                                file_size,
                                compute_check_sum);
                }
            }
        }

    } // ITERATE

    }}

    if ( (flags & CLDS_Manager::fRecurseMask) == CLDS_Manager::fDontRecurse )
        return;

    // Scan sub-directories

    {{

    CDir::TEntries  content(dir.GetEntries());
    ITERATE(CDir::TEntries, i, content) {

        if ((*i)->IsDir()) {
            string name = (*i)->GetName();

            if (name == "LDS" || name == "." || name == "..") {
                continue;
            }
            string entry = (*i)->GetPath();

            x_SyncWithDir(entry,
                          deleted,
                          updated,
                          scanned_files,
                          flags);

        }
    } // ITERATE

    }}
}