示例#1
0
  DataStatus DataPointGFAL::do_stat(const URL& stat_url, FileInfo& file) {
    struct stat st;
    int res;
    {
      GFALEnvLocker gfal_lock(usercfg, lfc_host);
      res = gfal_stat(GFALUtils::GFALURL(stat_url).c_str(), &st);
    }
    if (res < 0) {
      logger.msg(VERBOSE, "gfal_stat failed: %s", StrError(gfal_posix_code_error()));
      int error_no = GFALUtils::HandleGFALError(logger);
      return DataStatus(DataStatus::StatError, error_no);
    }

    if(S_ISREG(st.st_mode)) {
      file.SetType(FileInfo::file_type_file);
    } else if(S_ISDIR(st.st_mode)) {
      file.SetType(FileInfo::file_type_dir);
    } else {
      file.SetType(FileInfo::file_type_unknown);
    }

    std::string path = stat_url.Path();
    // For SRM the path can be given as SFN HTTP Option
    if ((stat_url.Protocol() == "srm" && !stat_url.HTTPOption("SFN").empty())) path = stat_url.HTTPOption("SFN");

    std::string name = Glib::path_get_basename(path);
    file.SetName(name);

    file.SetSize(st.st_size);
    file.SetModified(st.st_mtime);
    file.SetMetaData("atime", (Time(st.st_atime)).str());
    file.SetMetaData("ctime", (Time(st.st_ctime)).str());

    std::string perms;
    if (st.st_mode & S_IRUSR) perms += 'r'; else perms += '-';
    if (st.st_mode & S_IWUSR) perms += 'w'; else perms += '-';
    if (st.st_mode & S_IXUSR) perms += 'x'; else perms += '-';
    if (st.st_mode & S_IRGRP) perms += 'r'; else perms += '-';
    if (st.st_mode & S_IWGRP) perms += 'w'; else perms += '-';
    if (st.st_mode & S_IXGRP) perms += 'x'; else perms += '-';
    if (st.st_mode & S_IROTH) perms += 'r'; else perms += '-';
    if (st.st_mode & S_IWOTH) perms += 'w'; else perms += '-';
    if (st.st_mode & S_IXOTH) perms += 'x'; else perms += '-';
    file.SetMetaData("accessperm", perms);

    return DataStatus::Success;    
  }