Back to index

nordugrid-arc-nox  1.1.0~rc6
Functions
MkDirRecursive.h File Reference
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <arc/User.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int mkdir_recursive (const std::string &base_path, const std::string &path, mode_t mode, const Arc::User &user)

Function Documentation

int mkdir_recursive ( const std::string &  base_path,
const std::string &  path,
mode_t  mode,
const Arc::User user 
)

Definition at line 30 of file MkDirRecursive.cpp.

                                                      {
  std::string name = Glib::build_filename(base_path,path);
  std::string::size_type name_start = base_path.length();
  std::string::size_type name_end = name.length();
#ifdef WIN32
  // Skip disk:/ part of path if exists
  if(Glib::path_is_absolute(name)) {
    name_start = name_end - Glib::path_skip_root(name).length();
  }  
#endif
  /* go down */
  for (;;) {
    if ((mkdir_force(name.substr(0, name_end).c_str(), mode) == 0) ||
        (errno == EEXIST)) {
      if (errno != EEXIST)
        (lchown(name.substr(0, name_end).c_str(), user.get_uid(),
                user.get_gid()) != 0);
      /* go up */
      for (;;) {
        if (name_end >= name.length())
          return 0;
        name_end = name.find(G_DIR_SEPARATOR, name_end + 1);
        if (mkdir(name.substr(0, name_end).c_str(), mode) != 0) {
          if (errno == EEXIST)
            continue;
          return -1;
        }
        chmod(name.substr(0, name_end).c_str(), mode);
        (lchown(name.substr(0, name_end).c_str(), user.get_uid(),
                user.get_gid()) != 0);
      }
    }
    /* if(errno == EEXIST) { free(name); errno=EEXIST; return -1; } */
    if ((name_end = name.rfind(G_DIR_SEPARATOR, name_end - 1)) ==
        std::string::npos)
      break;
    if (name_end == name_start)
      break;
  }
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function: