Execute a filesystem command to create, delete or list a directory or to write out or read in a binary object to/from a file - as opposed to storing it in a repository.

Return TypeFunction nameArguments
hzEcodehdsExec::Filesys(hzChain&,hzHttpEvent*,)

Declared in file: hzDissemino.h
Defined in file : hdsExec.cpp

Function Logic:

0:START 1:items m_Action m_Resource m_Content 2:unknown 3:resource rc 4:unknown 5:items 6:Return rc 7:unknown 8:resource rc 9:unknown 10:items 11:Return rc 12:unknown 13:resource rc content 14:unknown 15:items 16:Return E_NODATA 17:items 18:unknown 19:items 20:Return E_WRITEFAIL 21:items 22:unknown 23:items 24:Return E_WRITEFAIL 25:items 26:Return E_OK 27:unknown 28:resource 29:unknown 30:items 31:Return E_NOTFOUND 32:unknown 33:items 34:Return E_TYPE 35:unknown 36:items 37:Return E_WRITEFAIL 38:Return E_OK 39:items 40:Return E_FORMAT

Function body:

hzEcode hdsExec::Filesys (hzChain& errorReport)hzHttpEvent* pE, 
{
   //  Execute a filesystem command to create, delete or list a directory or to write out or read in a binary object to/from a file - as opposed to storing it
   //  in a repository.
   _hzfunc("hdsExec::Filesys") ;
   FSTAT       fs ;            //  File/directory status
   hzAtom      atom ;          //  For obtaing file content
   hzChain     content ;       //  The file content (usually file upload)
   hzString    resource ;      //  The directory/file to operate on
   hzString    m_Action ;      //  The command specifier (mkdir|rmdir|save|delete)
   hzString    m_Resource ;    //  Directory resource to operate on
   hzString    m_Content ;     //  Save command only - specifies data to be saved
   hzEcode     rc = E_OK ;     //  Return value
   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")
   {
       //  Will work even if directory not empy
       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")
   {
       //  Write out data to a file.
       //  Obtain file name
       resource = m_pApp->ConvertText(m_Resource, pE) ;
       //  Obtain file content
       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 ;    //  Output stream
       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")
   {
       //  Delete a file
       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 ;
   }
   //  List entries in a directory
   errorReport.Printf("Filesys command Failed: Action %s illegal\n", *m_Action) ;
   return E_FORMAT ;
}