Loading...
Searching...
No Matches
XrdPfcFsTraversal.hh
Go to the documentation of this file.
#ifndef __XRDPFC_FSTRAVERSAL_HH__
#define __XRDPFC_FSTRAVERSAL_HH__
#include "XrdOss/XrdOssAt.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sys/stat.h>
class XrdOss;
class XrdOssDF;
namespace XrdPfc {
struct DirState;
class FsTraversal
{
public:
struct FilePairStat {
struct stat stat_data, stat_cinfo;
bool has_data = false;
bool has_cinfo = false;
void set_data (const struct stat &s) { stat_data = s; has_data = true; }
void set_cinfo(const struct stat &s) { stat_cinfo = s; has_cinfo = true; }
bool has_both() const { return has_data && has_cinfo; }
};
protected:
XrdOss &m_oss;
XrdOssAt m_oss_at;
XrdOucEnv m_env;
bool m_maintain_dirstate = false;
public:
DirState *m_root_dir_state = nullptr;
DirState *m_dir_state = nullptr; // current DirState
int m_rel_dir_level = -1; // dir level relative to root, 0 ~ at root
std::string m_current_path; // Includes trailing '/' -- needed for printouts and PurgeCandidate creation.
// Hmmh ... need a stack of those ... or not, if doing tail recursion.
// Can not, OpenDirAt descend can not be like that, ie, i will need the old handle.
std::vector<XrdOssDF*> m_dir_handle_stack;
std::vector<std::string> m_current_dirs; // swap out into local scope before recursion
std::map<std::string, FilePairStat> m_current_files; // clear when done
std::set<std::string> m_protected_top_dirs; // directories that will NOT be traversed at relative level 0.
static const char *m_traceID;
void slurp_current_dir();
void slurp_dir_ll(XrdOssDF &dh, int dir_level, const char *path, const char *trc_pfx);
public:
FsTraversal(XrdOss &oss);
~FsTraversal();
bool begin_traversal(DirState *root, const char *root_path);
bool begin_traversal(const char *root_path);
void end_traversal();
bool cd_down(const std::string &dir_name);
void cd_up();
int open_at_ro(const char* fname, XrdOssDF *&ossDF) {
return m_oss_at.OpenRO(*m_dir_handle_stack.back(), fname, m_env, ossDF);
}
int unlink_at(const char* fname) {
return m_oss_at.Unlink(*m_dir_handle_stack.back(), fname);
}
int close_delete(XrdOssDF *&ossDF);
XrdOucEnv& default_env() { return m_env; }
};
}
#endif
XrdOssAt.hh
XrdOucEnv.hh
stat
#define stat(a, b)
Definition XrdPosix.hh:101
XrdOssAt
Definition XrdOssAt.hh:62
XrdOssDF
Definition XrdOss.hh:63
XrdOss
Definition XrdOss.hh:499
XrdOucEnv
Definition XrdOucEnv.hh:42
XrdPfc::FsTraversal::m_current_dirs
std::vector< std::string > m_current_dirs
Definition XrdPfcFsTraversal.hh:51
XrdPfc::FsTraversal::open_at_ro
int open_at_ro(const char *fname, XrdOssDF *&ossDF)
Definition XrdPfcFsTraversal.hh:72
XrdPfc::FsTraversal::slurp_current_dir
void slurp_current_dir()
Definition XrdPfcFsTraversal.cc:137
XrdPfc::FsTraversal::m_current_path
std::string m_current_path
Definition XrdPfcFsTraversal.hh:45
XrdPfc::FsTraversal::m_dir_handle_stack
std::vector< XrdOssDF * > m_dir_handle_stack
Definition XrdPfcFsTraversal.hh:49
XrdPfc::FsTraversal::close_delete
int close_delete(XrdOssDF *&ossDF)
Definition XrdPfcFsTraversal.cc:30
XrdPfc::FsTraversal::m_maintain_dirstate
bool m_maintain_dirstate
Definition XrdPfcFsTraversal.hh:38
XrdPfc::FsTraversal::m_rel_dir_level
int m_rel_dir_level
Definition XrdPfcFsTraversal.hh:44
XrdPfc::FsTraversal::FsTraversal
FsTraversal(XrdOss &oss)
Definition XrdPfcFsTraversal.cc:23
XrdPfc::FsTraversal::m_oss
XrdOss & m_oss
Definition XrdPfcFsTraversal.hh:34
XrdPfc::FsTraversal::end_traversal
void end_traversal()
Definition XrdPfcFsTraversal.cc:76
XrdPfc::FsTraversal::cd_up
void cd_up()
Definition XrdPfcFsTraversal.cc:119
XrdPfc::FsTraversal::slurp_dir_ll
void slurp_dir_ll(XrdOssDF &dh, int dir_level, const char *path, const char *trc_pfx)
Definition XrdPfcFsTraversal.cc:147
XrdPfc::FsTraversal::m_oss_at
XrdOssAt m_oss_at
Definition XrdPfcFsTraversal.hh:35
XrdPfc::FsTraversal::begin_traversal
bool begin_traversal(DirState *root, const char *root_path)
Definition XrdPfcFsTraversal.cc:43
XrdPfc::FsTraversal::m_env
XrdOucEnv m_env
Definition XrdPfcFsTraversal.hh:36
XrdPfc::FsTraversal::unlink_at
int unlink_at(const char *fname)
Definition XrdPfcFsTraversal.hh:75
XrdPfc::FsTraversal::~FsTraversal
~FsTraversal()
Definition XrdPfcFsTraversal.cc:27
XrdPfc::FsTraversal::m_dir_state
DirState * m_dir_state
Definition XrdPfcFsTraversal.hh:42
XrdPfc::FsTraversal::m_protected_top_dirs
std::set< std::string > m_protected_top_dirs
Definition XrdPfcFsTraversal.hh:54
XrdPfc::FsTraversal::m_root_dir_state
DirState * m_root_dir_state
Definition XrdPfcFsTraversal.hh:41
XrdPfc::FsTraversal::cd_down
bool cd_down(const std::string &dir_name)
Definition XrdPfcFsTraversal.cc:96
XrdPfc::FsTraversal::default_env
XrdOucEnv & default_env()
Definition XrdPfcFsTraversal.hh:80
XrdPfc::FsTraversal::m_current_files
std::map< std::string, FilePairStat > m_current_files
Definition XrdPfcFsTraversal.hh:52
XrdPfc::FsTraversal::m_traceID
static const char * m_traceID
Definition XrdPfcFsTraversal.hh:56
XrdPfc
Definition XrdPfc.hh:41
XrdPfc::DirState
Definition XrdPfcDirState.hh:56
XrdPfc::FsTraversal::FilePairStat
Definition XrdPfcFsTraversal.hh:23
XrdPfc::FsTraversal::FilePairStat::set_data
void set_data(const struct stat &s)
Definition XrdPfcFsTraversal.hh:28
XrdPfc::FsTraversal::FilePairStat::has_cinfo
bool has_cinfo
Definition XrdPfcFsTraversal.hh:26
XrdPfc::FsTraversal::FilePairStat::has_both
bool has_both() const
Definition XrdPfcFsTraversal.hh:30
XrdPfc::FsTraversal::FilePairStat::stat_cinfo
struct stat stat_data stat_cinfo
Definition XrdPfcFsTraversal.hh:24
XrdPfc::FsTraversal::FilePairStat::set_cinfo
void set_cinfo(const struct stat &s)
Definition XrdPfcFsTraversal.hh:29
XrdPfc::FsTraversal::FilePairStat::has_data
bool has_data
Definition XrdPfcFsTraversal.hh:25