cmn_TreeWalk Class Reference
[Common, basic classes, functions and types]

#include <cmn_TreeWalk.h>

Inheritance diagram for cmn_TreeWalk:

Inheritance graph
[legend]
Collaboration diagram for cmn_TreeWalk:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 73 of file cmn_TreeWalk.h.


Public Member Functions

 cmn_TreeWalk (const cmn_Path &a_stackStorage, bool &a_abort)
virtual ~cmn_TreeWalk ()
void Start (const cmn_Path &a_mountPoint)

Public Attributes

 log_CLASSID_m

Protected Member Functions

virtual void CheckDir (bool a_mountpoint, const cmn_Path &a_dirPath, ivd_GenInode_t a_fileInode)=0
 When check dir is called then process current dir is checked directory.
bool DoWalk (const cmn_Path &a_path, ivd_GenInode_t a_ownInode, bool a_mountpoint)
 return false if can't reposition previous directory
fname_inode_vec_tGetLastVector ()
int GetStackSize ()
void SaveStack ()
 a saved stack is need at continue mode.

Protected Attributes

const bool & m_abort

Private Member Functions

void PushDentries (const cmn_Path &a_path, ivd_GenInode_t a_ownInode)
bool RewindStack (const cmn_Path &a_path, const unsigned int a_level)
 return false if can't reposition previous directory
void LoadStack (ifstream &a_infs)

Private Attributes

const cmn_Path m_stackStorage
fname_inode_vec_vec_t m_deStack
ofstream m_outfs

Constructor & Destructor Documentation

cmn_TreeWalk::cmn_TreeWalk ( const cmn_Path a_stackStorage,
bool &  a_abort 
)

Definition at line 111 of file cmn_TreeWalk.cpp.

References dbg_DETAIL, LoadStack(), log_DBG_m, log_FUNC_m, m_deStack, and m_stackStorage.

00114     :
00115     m_stackStorage(a_stackStorage),
00116     m_abort(a_abort)
00117 {
00118     log_FUNC_m(cmn_TreeWalk);
00119     // max supported directory tree depth
00120     // TODO: redesign treewalk and unfold recursion
00121     m_deStack.reserve(200);
00122 
00123     ifstream infs(m_stackStorage.c_str());
00124     if (infs) {
00125         log_DBG_m(dbg_DETAIL,  " Load stack." );
00126         try {
00127             LoadStack(infs);
00128         }
00129         catch (ivd_Error) {  // can't read stack file, continue without Stack file from scratch
00130 
00131             m_deStack.clear();
00132             m_deStack.reserve(200);
00133         }
00134         infs.close();
00135     }
00136 }
//============================================================================//

Here is the call graph for this function:

virtual cmn_TreeWalk::~cmn_TreeWalk (  )  [inline, virtual]

Definition at line 79 of file cmn_TreeWalk.h.

00079 {};


Member Function Documentation

void cmn_TreeWalk::Start ( const cmn_Path a_mountPoint  ) 

Definition at line 140 of file cmn_TreeWalk.cpp.

References cmn_File::DeleteFile(), DoWalk(), log_FUNC_A_m, m_abort, m_deStack, m_stackStorage, and RewindStack().

Referenced by Backup(), i_HSM_i::CheckFSCvsIVDFS(), and i_HSM_i::MigrateByAPI().

00140                                                      {
00141     log_FUNC_A_m(Start, "path: " << a_mountPoint);
00142 
00143     if (m_deStack.size() != 0) {
00144         RewindStack(a_mountPoint, 1);
00145     }
00146     else {
00147         DoWalk(a_mountPoint, 0, true);
00148     }
00149     if (!m_abort) {
00150         try {
00151             cmn_File::DeleteFile(m_stackStorage);
00152         }
00153         catch (ivd_SysError) {  // file is not generated
00154             return;
00155         }
00156     }
00157 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void cmn_TreeWalk::CheckDir ( bool  a_mountpoint,
const cmn_Path a_dirPath,
ivd_GenInode_t  a_fileInode 
) [protected, pure virtual]

When check dir is called then process current dir is checked directory.

Implemented in MigrateTreewalk, and TreeWalk.

Referenced by DoWalk(), and RewindStack().

Here is the caller graph for this function:

bool cmn_TreeWalk::DoWalk ( const cmn_Path a_path,
ivd_GenInode_t  a_ownInode,
bool  a_mountpoint 
) [protected]

return false if can't reposition previous directory

Definition at line 199 of file cmn_TreeWalk.cpp.

References CheckDir(), dbg_DETAIL, IVD_PRINT_ID_FS, log_DBG_m, log_FUNC_A_m, m_deStack, and PushDentries().

Referenced by TreeWalkBackup::CheckDir(), TreeWalk::CheckDir(), MigrateTreewalk::CheckDir(), and Start().

00201                                                    {
00202 
00203     log_FUNC_A_m(DoWalk, "a_path:" << a_path << ", a_ownInode:" << 
00204                          IVD_PRINT_ID_FS(a_ownInode) <<
00205                          "a_mountpoint" << boolalpha << a_mountpoint);
00206 
00207     m_deStack.push_back(fname_inode_vec_t());
00208     PushDentries(a_path, a_ownInode);
00209 
00210     log_DBG_m(dbg_DETAIL, "a_ownInode:" << a_ownInode <<
00211                           ", a_path:" << a_path);
00212                           
00213     CheckDir(a_mountpoint, a_path, 0);
00214 
00215     m_deStack.pop_back();
00216 
00217     return true;
00218 }

Here is the call graph for this function:

Here is the caller graph for this function:

fname_inode_vec_t& cmn_TreeWalk::GetLastVector (  )  [inline, protected]

Definition at line 107 of file cmn_TreeWalk.h.

Referenced by TreeWalkBackup::CheckDir(), TreeWalk::CheckDir(), and MigrateTreewalk::CheckDir().

00107 { return m_deStack.back();};

Here is the caller graph for this function:

int cmn_TreeWalk::GetStackSize (  )  [inline, protected]

Definition at line 108 of file cmn_TreeWalk.h.

Referenced by TreeWalk::TreeWalk().

00108 { return (UInt32_t)m_deStack.size();};

Here is the caller graph for this function:

void cmn_TreeWalk::SaveStack ( void   )  [protected]

a saved stack is need at continue mode.

this method have to be called after each batch finished

Definition at line 252 of file cmn_TreeWalk.cpp.

References log_FUNC_m, m_deStack, m_outfs, and m_stackStorage.

Referenced by TreeWalkBackup::CheckDir(), and TreeWalk::CheckDir().

00252                                  {
00253     log_FUNC_m(SaveStack);
00254     m_outfs.open(m_stackStorage.c_str());
00255     for(fname_inode_vec_vec_t::const_iterator i = m_deStack.begin();
00256         i != m_deStack.end(); i++) {
00257         m_outfs << *i;
00258     }
00259     m_outfs.close();
00260 }

Here is the caller graph for this function:

void cmn_TreeWalk::PushDentries ( const cmn_Path a_path,
ivd_GenInode_t  a_ownInode 
) [private]

Definition at line 161 of file cmn_TreeWalk.cpp.

References dbg_NORM, ivd_BaseException::GetFriendly(), cmn_FastDirLst::GetNextName(), HSMFS_DBDIR, ift_DIR, log_DBG_m, log_FUNC_m, m_deStack, fname_inode_t::m_fileType, fname_inode_t::m_iNode, and fname_inode_t::m_name.

Referenced by DoWalk().

00161                                                                                  {
00162     log_FUNC_m(PushDentries);
00163 
00164     try {
00165         cmn_FastDirLst dirList(a_path);
00166         fname_inode_t fInfo;
00167 
00168         fname_inode_vec_t &de = m_deStack.back();
00169 
00170         fInfo.m_name = dirList.GetNextName(fInfo.m_iNode, fInfo.m_fileType);
00171         while (fInfo.m_name.length() != 0)
00172         {
00173 #if TGT_OS_hpux
00174 // TODO: Create general solution for skipping directories and files.
00175             if (   a_ownInode == 0
00176                 && fInfo.m_fileType == ift_DIR
00177                 && fInfo.m_name == HSMFS_DBDIR) {
00178                 log_DBG_m(dbg_NORM, "Skipping .hsmfs");
00179             }
00180             else 
00181 #endif
00182             if (   fInfo.m_iNode != 0  // not proper file, example: Windows special file
00183                 && fInfo.m_name  != "." 
00184                 && fInfo.m_name  != "..") {
00185                 de.push_back(fInfo);
00186             }
00187             fInfo.m_name = dirList.GetNextName(fInfo.m_iNode, fInfo.m_fileType);
00188         }
00189     }
00190     catch (const ivd_SysError& se) {  // dir is probably deleted
00191         log_DBG_m(dbg_NORM, 
00192             "Continue, error opening dir " << a_path << " :" << se.GetFriendly());
00193         return; // can't read the dir, so it's done
00194     }
00195 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmn_TreeWalk::RewindStack ( const cmn_Path a_path,
const unsigned int  a_level 
) [private]

return false if can't reposition previous directory

Definition at line 222 of file cmn_TreeWalk.cpp.

References CheckDir(), dbg_DETAIL, log_DBG_m, log_FUNC_A_m, m_deStack, fname_inode_t::m_iNode, and fname_inode_t::m_name.

Referenced by Start().

00222                                                                                  {
00223     log_FUNC_A_m(RewindStack, " Path:" << a_path << " a_level:" << a_level);
00224 
00225 
00226     fname_inode_t lastLevel = m_deStack[a_level-1].back();
00227     
00228 
00229     if (a_level < m_deStack.size()) {
00230         if (!RewindStack(a_path + lastLevel.m_name, a_level+1)) {
00231             goto end; // can't return to dir, skip it
00232         }
00233         m_deStack[a_level-1].pop_back();
00234     }
00235 
00236     log_DBG_m(dbg_DETAIL, "lastLevel.m_iNode:" << lastLevel.m_iNode <<
00237                           ", a_path:" << a_path);
00238     if (a_level == 1) { //rewind stack to root
00239         CheckDir(true, a_path, lastLevel.m_iNode);
00240     } else {
00241         CheckDir(false, a_path, lastLevel.m_iNode);
00242     }
00243 
00244 end:
00245     m_deStack.pop_back();
00246 
00247     return true;
00248 }

Here is the call graph for this function:

Here is the caller graph for this function:

void cmn_TreeWalk::LoadStack ( ifstream &  a_infs  )  [private]

Definition at line 264 of file cmn_TreeWalk.cpp.

References log_FUNC_m, and m_deStack.

Referenced by cmn_TreeWalk().

00264                                              {
00265     log_FUNC_m(LoadStack);
00266 
00267     while(a_infs.eof() != true) {
00268         m_deStack.push_back(fname_inode_vec_t());
00269         a_infs >> m_deStack.back();
00270     }
00271     m_deStack.pop_back();
00272 }

Here is the caller graph for this function:


Member Data Documentation

Reimplemented in TreeWalkBackup, MigrateTreewalk, TreeWalk, CreateTree, RecAccess, RecOpen, and RecRemove.

Definition at line 79 of file cmn_TreeWalk.h.

Definition at line 85 of file cmn_TreeWalk.h.

Referenced by cmn_TreeWalk(), SaveStack(), and Start().

Definition at line 86 of file cmn_TreeWalk.h.

Referenced by cmn_TreeWalk(), DoWalk(), LoadStack(), PushDentries(), RewindStack(), SaveStack(), and Start().

ofstream cmn_TreeWalk::m_outfs [private]

Definition at line 87 of file cmn_TreeWalk.h.

Referenced by SaveStack().

const bool& cmn_TreeWalk::m_abort [protected]

Reimplemented in TreeWalkBackup.

Definition at line 90 of file cmn_TreeWalk.h.

Referenced by TreeWalk::CheckDir(), TreeWalk::Report(), and Start().


The documentation for this class was generated from the following files:

Generated on Mon Feb 27 19:05:57 2012 for OPENARCHIVE by  doxygen 1.5.6