| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdsExec::Filesys | (hzChain&,hzHttpEvent*,) |
Declared in file: hzDissemino.h
Defined in file : hdsExec.cpp
Function Logic:
Function body:
hzEcode hdsExec::Filesys (hzChain& errorReport, hzHttpEvent* pE)
{
_hzfunc("hdsExec::Filesys") ;
FSTAT fs ;
hzAtom atom ;
hzChain content ;
hzString resource ;
hzString m_Action ;
hzString m_Resource ;
hzString m_Content ;
hzEcode rc = E_OK ;
errorReport.Printf("Filesys action %s and resource %s\n", *m_Action, *m_Resource) ;
m_Action = m_pApp->m_ExecParams[m_FstParam] ;
m_Resource = m_pApp->m_ExecParams[m_FstParam] ;
m_Content = m_pApp->m_ExecParams[m_FstParam] ;
if (m_Action == "mkdir")
{
resource = m_pApp->ConvertText(m_Resource, pE) ;
rc = AssertDir(resource, 0777);
if (rc != E_OK)
errorReport.Printf("Could not assert dir %s error is %s\n", *resource, Err2Txt(rc)) ;
return rc ;
}
if (m_Action == "rmdir")
{
resource = m_pApp->ConvertText(m_Resource, pE) ;
rc = BlattDir(resource) ;
if (rc != E_OK)
errorReport.Printf("Could not blatt dir %s error is %s\n", *resource, Err2Txt(rc)) ;
return rc ;
}
if (m_Action == "save")
{
resource = m_pApp->ConvertText(m_Resource, pE) ;
rc = m_pApp->PcEntConv(atom, m_Content, pE) ;
content = atom.Chain() ;
if (!content.Size())
{
errorReport.Printf("No data to write to file %s\n", *resource) ;
return E_NODATA ;
}
ofstream os ;
os.open(*resource) ;
if (os.fail())
{ errorReport.Printf("Could not open for write, file %s\n", *resource) ; return E_WRITEFAIL ; }
os << content ;
if (os.fail())
{ errorReport.Printf("Could not write, file %s\n", *resource) ; return E_WRITEFAIL ; }
os.close() ;
return E_OK ;
}
if (m_Action == "delete")
{
resource = m_pApp->ConvertText(m_Resource, pE) ;
if (lstat(*resource, &fs) < 0)
{ errorReport.Printf("Action DELETE Failed: File %s not found\n", *resource) ; return E_NOTFOUND ; }
if (ISDIR(fs.st_mode))
{ errorReport.Printf("Action DELETE Failed: %s is a directory\n", *resource) ; return E_TYPE ; }
if (unlink(*resource) < 0)
{ errorReport.Printf("Action DELETE Failed: File %s could not be deleted\n", *resource) ; return E_WRITEFAIL ; }
return E_OK ;
}
errorReport.Printf("Filesys command Failed: Action %s illegal\n", *m_Action) ;
return E_SYNTAX ;
}