Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes

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.

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

Detailed Description

Definition at line 87 of file cmn_TreeWalk.h.


Constructor & Destructor Documentation

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

Definition at line 125 of file cmn_TreeWalk.cpp.

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

    :
    m_stackStorage(a_stackStorage),
    m_abort(a_abort)
{
    log_FUNC_m(cmn_TreeWalk);
    // max supported directory tree depth
    // TODO: redesign treewalk and unfold recursion
    m_deStack.reserve(200);

    ifstream infs(m_stackStorage.c_str());
    if (infs) {
        log_DBG_m(dbg_DETAIL,  " Load stack." );
        try {
            LoadStack(infs);
        }
        catch (ivd_Error) {  // can't read stack file, continue without Stack file from scratch

            m_deStack.clear();
            m_deStack.reserve(200);
        }
        infs.close();
    }
}

Here is the call graph for this function:

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

Definition at line 93 of file cmn_TreeWalk.h.

{};


Member Function Documentation

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 213 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().

                                                   {

    log_FUNC_A_m(DoWalk, "a_path:" << a_path << ", a_ownInode:" << 
                         IVD_PRINT_ID_FS(a_ownInode) <<
                         "a_mountpoint" << boolalpha << a_mountpoint);

    m_deStack.push_back(fname_inode_vec_t());
    PushDentries(a_path, a_ownInode);

    log_DBG_m(dbg_DETAIL, "a_ownInode:" << a_ownInode <<
                          ", a_path:" << a_path);
                          
    CheckDir(a_mountpoint, a_path, 0);

    m_deStack.pop_back();

    return true;
}

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 121 of file cmn_TreeWalk.h.

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

{ return m_deStack.back();};

Here is the caller graph for this function:

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

Definition at line 122 of file cmn_TreeWalk.h.

Referenced by TreeWalk::TreeWalk().

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

Here is the caller graph for this function:

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

Definition at line 278 of file cmn_TreeWalk.cpp.

References log_FUNC_m, and m_deStack.

Referenced by cmn_TreeWalk().

                                             {
    log_FUNC_m(LoadStack);

    while(a_infs.eof() != true) {
        m_deStack.push_back(fname_inode_vec_t());
        a_infs >> m_deStack.back();
    }
    m_deStack.pop_back();
}

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 175 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().

                                                                                 {
    log_FUNC_m(PushDentries);

    try {
        cmn_FastDirLst dirList(a_path);
        fname_inode_t fInfo;

        fname_inode_vec_t &de = m_deStack.back();

        fInfo.m_name = dirList.GetNextName(fInfo.m_iNode, fInfo.m_fileType);
        while (fInfo.m_name.length() != 0)
        {
#if TGT_OS_hpux
// TODO: Create general solution for skipping directories and files.
            if (   a_ownInode == 0
                && fInfo.m_fileType == ift_DIR
                && fInfo.m_name == HSMFS_DBDIR) {
                log_DBG_m(dbg_NORM, "Skipping .hsmfs");
            }
            else 
#endif
            if (   fInfo.m_iNode != 0  // not proper file, example: Windows special file
                && fInfo.m_name  != "." 
                && fInfo.m_name  != "..") {
                de.push_back(fInfo);
            }
            fInfo.m_name = dirList.GetNextName(fInfo.m_iNode, fInfo.m_fileType);
        }
    }
    catch (const ivd_SysError& se) {  // dir is probably deleted
        log_DBG_m(dbg_NORM, 
            "Continue, error opening dir " << a_path << " :" << se.GetFriendly());
        return; // can't read the dir, so it's done
    }
}

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 236 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().

                                                                                 {
    log_FUNC_A_m(RewindStack, " Path:" << a_path << " a_level:" << a_level);


    fname_inode_t lastLevel = m_deStack[a_level-1].back();
    

    if (a_level < m_deStack.size()) {
        if (!RewindStack(a_path + lastLevel.m_name, a_level+1)) {
            goto end; // can't return to dir, skip it
        }
        m_deStack[a_level-1].pop_back();
    }

    log_DBG_m(dbg_DETAIL, "lastLevel.m_iNode:" << lastLevel.m_iNode <<
                          ", a_path:" << a_path);
    if (a_level == 1) { //rewind stack to root
        CheckDir(true, a_path, lastLevel.m_iNode);
    } else {
        CheckDir(false, a_path, lastLevel.m_iNode);
    }

end:
    m_deStack.pop_back();

    return true;
}

Here is the call graph for this function:

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 266 of file cmn_TreeWalk.cpp.

References log_FUNC_m, m_deStack, m_outfs, and m_stackStorage.

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

                                 {
    log_FUNC_m(SaveStack);
    m_outfs.open(m_stackStorage.c_str());
    for(fname_inode_vec_vec_t::const_iterator i = m_deStack.begin();
        i != m_deStack.end(); i++) {
        m_outfs << *i;
    }
    m_outfs.close();
}

Here is the caller graph for this function:

void cmn_TreeWalk::Start ( const cmn_Path a_mountPoint  ) 

Definition at line 154 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().

                                                     {
    log_FUNC_A_m(Start, "path: " << a_mountPoint);

    if (m_deStack.size() != 0) {
        RewindStack(a_mountPoint, 1);
    }
    else {
        DoWalk(a_mountPoint, 0, true);
    }
    if (!m_abort) {
        try {
            cmn_File::DeleteFile(m_stackStorage);
        }
        catch (ivd_SysError) {  // file is not generated
            return;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented in TreeWalkBackup, MigrateTreewalk, and TreeWalk.

Definition at line 93 of file cmn_TreeWalk.h.

const bool& cmn_TreeWalk::m_abort [protected]

Reimplemented in TreeWalkBackup.

Definition at line 104 of file cmn_TreeWalk.h.

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

ofstream cmn_TreeWalk::m_outfs [private]

Definition at line 101 of file cmn_TreeWalk.h.

Referenced by SaveStack().

Definition at line 99 of file cmn_TreeWalk.h.

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


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