CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
data_dir_mgmt.cc
Go to the documentation of this file.
1 
4 #include "data_dir_mgmt.h"
5 
6 #include <errno.h>
7 #include <stdio.h>
8 
9 #include "helpers.h"
11 #include "util/posix.h"
12 
17  std::string cur_path,
18  mode_t mode,
19  unsigned depth = 1)
20 {
21  std::string max_dir_name = std::string(kDigitsPerDirLevel, 'f');
22  // Build current base path
23  if (depth == 1) {
24  bool res1 = MkdirDeep(cur_path.c_str(), mode);
25  assert(res1);
26  } else {
27  int res = mkdir(cur_path.c_str(), mode);
28  assert(res == 0 || errno == EEXIST);
29  }
30  // Build template for directory names:
32  char hex[kDigitsPerDirLevel+1];
33  char dir_name_template[5];
34  snprintf(dir_name_template,
35  sizeof(dir_name_template),
36  "%%%02ux",
38  // Go through all levels:
39  for (; depth <= kDirLevels; depth++) {
40  if (!DirectoryExists(cur_path+"/"+max_dir_name)) {
41  // Directories in this level not yet fully created...
42  for (unsigned int i = 0;
43  i < (((unsigned int) 1) << 4*kDigitsPerDirLevel);
44  i++) {
45  // Go through directories 0^kDigitsPerDirLevel to f^kDigitsPerDirLevel
46  snprintf(hex, sizeof(hex), dir_name_template, i);
47  std::string this_path = cur_path + "/" + std::string(hex);
48  int res = mkdir(this_path.c_str(), mode);
49  assert(res == 0 || errno == EEXIST);
50  // Once directory created: Prepare substructures
51  PosixCheckDirStructure(this_path, mode, depth+1);
52  }
53  break;
54  } else {
55  // Directories on this level fully created; check ./
56  PosixCheckDirStructure(cur_path+"/"+max_dir_name, mode, depth+1);
57  }
58  }
59 }
60 
62  // NOTE(steuber): Can we do this in parallel?
63  PosixCheckDirStructure(ctx->data, 0700);
64 }
struct cvmcache_context * ctx
assert((mem||(size==0))&&"Out Of Memory")
void InitializeDataDirectory(struct fs_traversal_context *ctx)
void PosixCheckDirStructure(std::string cur_path, mode_t mode, unsigned depth=1)
const unsigned kDigitsPerDirLevel
Definition: helpers.h:22
bool MkdirDeep(const std::string &path, const mode_t mode, bool verify_writable)
Definition: posix.cc:871
const unsigned kDirLevels
Definition: helpers.h:21
bool DirectoryExists(const std::string &path)
Definition: posix.cc:838