Initialize the hdbBinRepos instance. This ensures the working directory exists and both the index and data file exist. Note that this function does not leave index or data files open. This is left to hdbBinRepos::Open() as a separate step. Errors: Any false return is due to an irrecoverable error. The calling function must check the return value.

Return TypeFunction nameArguments
hzEcodehdbBinRepos::Init(hzString&,hzString&,)

Declared in file: hzDatabase.h
Defined in file : hdbBinRepos.cpp

Function Logic:

0:START 1:unknown 2:Return hzerr(E_INITDUP,Resource already initialized) 3:unknown 4:Return hzerr(E_ARGUMENT,No name) 5:unknown 6:Return hzerr(E_ARGUMENT,Repository %s: No working directory,*name) 7:unknown 8:Return hzerr(E_DUPLICATE,Binary datum cron %s already exists,*name) 9:m_Name m_Workdir items 10:unknown 11:rc 12:unknown 13:Return hzerr(rc,Could not assert working dir of %s,*m_Workdir) 14:m_Name 15:/ 16:m_Workdir 17:m_FileIndx m_Name / m_Workdir m_FileData 18:unknown 19:m_nPopulation 20:m_nSeqId 21:fs 22:m_nPopulation 23:m_nSeqId 24:unknown 25:m_nSize 26:m_nSize 27:items rc items m_nInitState 28:Return E_OK

Function body:

hzEcode hdbBinRepos::Init (hzString& name)hzString& opdir, 
{
   //  Initialize the hdbBinRepos instance. This ensures the working directory exists and both the index and data file exist.
   //  
   //  Note that this function does not leave index or data files open. This is left to hdbBinRepos::Open() as a separate step.
   //  
   //  Arguments: 1) name  Name of object set to be stored in the hdbBinRepos (will be base of the two filenames)
   //     2) opdir Full pathname of operational directory
   //  
   //  Returns: E_OPENFAIL The files could not be opened or created (no space or wrong permissions)
   //     E_OK  Operation was successful.
   //  
   //  Errors:  Any false return is due to an irrecoverable error. The calling function
   //     must check the return value.
   _hzfunc("hdbBinRepos::Init") ;
   FSTAT       fs ;        //  File status
   ifstream    is ;        //  Input stream for reading index file
   hzEcode     rc ;        //  Return code
   if (m_nInitState)
       return hzerr(E_INITDUP, "Resource already initialized") ;
   //  Check we have a name and working directory
   if (!name)  return hzerr(E_ARGUMENT, "No name") ;
   if (!opdir) return hzerr(E_ARGUMENT, "Repository %s: No working directory", *name) ;
   //  Check we do not already have a datacron of the name
   if (m_pADP->GetBinRepos(name))
       return hzerr(E_DUPLICATE, "Binary datum cron %s already exists", *name) ;
   //  Assign internal structure, name and working directory
   m_Name = name ;
   m_Workdir = opdir ;
   threadLog("Name %s workdir %s\n", *m_Name, *m_Workdir) ;
   //  Assert working directory
   if (lstat(*m_Workdir, &fs) == -1)
   {
       rc = AssertDir(*m_Workdir, 0777);
       if (rc != E_OK)
           return hzerr(rc, "Could not assert working dir of %s", *m_Workdir) ;
   }
   //  Set the pathnames for the index and data file
   m_FileIndx = m_Workdir + "/" + m_Name + ".idx" ;
   m_FileData = m_Workdir + "/" + m_Name + ".dat" ;
   if (lstat(*m_FileIndx, &fs) == -1)
       m_nSeqId = m_nPopulation = 0;
   else
       m_nSeqId = m_nPopulation = (uint32_t) (fs.st_size / sizeof(_datum_hd)) ;    //  & 0xffffffff ;
   if (lstat(*m_FileData, &fs) == -1)
       m_nSize = 0;
   else
       m_nSize = fs.st_size ;
   //  Set init state etc
   threadLog("A Initialized %s (%p) count %u (size %u) with err=%s\n", *m_Name, this, Count(), m_nSize, Err2Txt(rc)) ;
   rc = m_pADP->RegisterBinRepos(this) ;
   threadLog("B Initialized %s (%p) count %d with files %s and %s. err=%s\n",
       *m_Name, this, m_pADP->CountBinRepos(), *m_FileIndx, *m_FileData, Err2Txt(rc)) ;
   m_nInitState = 1;
   return E_OK ;
}