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 Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbBinRepos::Init | (hzString&,hzString&,) |
Declared in file: hzDatabase.h
Defined in file : hdbBinRepos.cpp
Function Logic:
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 ;
}