XRootD
Loading...
Searching...
No Matches
XrdPfcFsTraversal.hh
Go to the documentation of this file.
1#ifndef __XRDPFC_FSTRAVERSAL_HH__
2#define __XRDPFC_FSTRAVERSAL_HH__
3
4#include "XrdOss/XrdOssAt.hh"
5#include "XrdOuc/XrdOucEnv.hh"
6
7#include <string>
8#include <vector>
9#include <map>
10#include <set>
11#include <sys/stat.h>
12
13class XrdOss;
14class XrdOssDF;
15
16namespace XrdPfc {
17
18struct DirState;
19
21{
22public:
23 struct FilePairStat {
24 struct stat stat_data, stat_cinfo;
25 bool has_data = false;
26 bool has_cinfo = false;
27
28 void set_data (const struct stat &s) { stat_data = s; has_data = true; }
29 void set_cinfo(const struct stat &s) { stat_cinfo = s; has_cinfo = true; }
30 bool has_both() const { return has_data && has_cinfo; }
31 };
32
33protected:
37
38 bool m_maintain_dirstate = false;
39
40public:
42 DirState *m_dir_state = nullptr; // current DirState
43
44 int m_rel_dir_level = -1; // dir level relative to root, 0 ~ at root
45 std::string m_current_path; // Includes trailing '/' -- needed for printouts and PurgeCandidate creation.
46
47 // Hmmh ... need a stack of those ... or not, if doing tail recursion.
48 // Can not, OpenDirAt descend can not be like that, ie, i will need the old handle.
49 std::vector<XrdOssDF*> m_dir_handle_stack;
50
51 std::vector<std::string> m_current_dirs; // swap out into local scope before recursion
52 std::map<std::string, FilePairStat> m_current_files; // clear when done
53
54 std::set<std::string> m_protected_top_dirs; // directories that will NOT be traversed at relative level 0.
55
56 static const char *m_traceID;
57
58 void slurp_current_dir();
59 void slurp_dir_ll(XrdOssDF &dh, int dir_level, const char *path, const char *trc_pfx);
60
61public:
62 FsTraversal(XrdOss &oss);
64
65 bool begin_traversal(DirState *root, const char *root_path);
66 bool begin_traversal(const char *root_path);
67 void end_traversal();
68
69 bool cd_down(const std::string &dir_name);
70 void cd_up();
71
72 int open_at_ro(const char* fname, XrdOssDF *&ossDF) {
73 return m_oss_at.OpenRO(*m_dir_handle_stack.back(), fname, m_env, ossDF);
74 }
75 int unlink_at(const char* fname) {
76 return m_oss_at.Unlink(*m_dir_handle_stack.back(), fname);
77 }
78 int close_delete(XrdOssDF *&ossDF);
79
81};
82
83}
84
85#endif
#define stat(a, b)
Definition XrdPosix.hh:101
std::vector< std::string > m_current_dirs
int open_at_ro(const char *fname, XrdOssDF *&ossDF)
std::vector< XrdOssDF * > m_dir_handle_stack
int close_delete(XrdOssDF *&ossDF)
void slurp_dir_ll(XrdOssDF &dh, int dir_level, const char *path, const char *trc_pfx)
bool begin_traversal(DirState *root, const char *root_path)
int unlink_at(const char *fname)
std::set< std::string > m_protected_top_dirs
bool cd_down(const std::string &dir_name)
std::map< std::string, FilePairStat > m_current_files
static const char * m_traceID
void set_data(const struct stat &s)
void set_cinfo(const struct stat &s)