当前位置: 首页>>代码示例>>C++>>正文


C++ Sector::mkdir方法代码示例

本文整理汇总了C++中Sector::mkdir方法的典型用法代码示例。如果您正苦于以下问题:C++ Sector::mkdir方法的具体用法?C++ Sector::mkdir怎么用?C++ Sector::mkdir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sector的用法示例。


在下文中一共展示了Sector::mkdir方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char** argv)
{
   if (argc != 2)
   {
      cerr << "USAGE: mkdir <dir>\n";
      return -1;
   }

   Sector client;

   Session s;
   s.loadInfo("../conf/client.conf");

   if (client.init(s.m_ClientConf.m_strMasterIP, s.m_ClientConf.m_iMasterPort) < 0)
      return -1;
   if (client.login(s.m_ClientConf.m_strUserName, s.m_ClientConf.m_strPassword, s.m_ClientConf.m_strCertificate.c_str()) < 0)
      return -1;

   int r = client.mkdir(argv[1]);
   if (r < 0)
      cerr << "ERROR: " << r << " " << SectorError::getErrorMsg(r) << endl;

   client.logout();
   client.close();

   return 1;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:27,代码来源:mkdir.cpp

示例2: main

int main(int argc, char** argv)
{
   if (argc != 2)
   {
      cerr << "USAGE: mkdir <dir>\n";
      return -1;
   }

   Sector client;
   if (Utility::login(client) < 0)
      return -1;

   int result = 0;

   if ((result = client.mkdir(argv[1])) < 0)
      Utility::print_error(result);

   Utility::logout(client);

   return result;
}
开发者ID:deniskin82,项目名称:sector-sphere,代码行数:21,代码来源:mkdir.cpp

示例3: main


//.........这里部分代码省略.........
         SNode s;
         if (LocalFS::stat(*param, s) < 0)
         {
            cerr << "ERROR: source file does not exist.\n";
            return -1;
         }

         if (s.m_bIsDir)
            prefix = *param;
         else
         {
            size_t pos = param->rfind('/');
            if (pos != string::npos)
               prefix = param->substr(0, pos);
         }

         getFileList(*param, fl);
      }
      else
      {
         size_t pos = param->rfind('/');
         if (pos != string::npos)
            prefix = param->substr(0, pos);

         string path = *param;
         string orig = path;
         size_t p = path.rfind('/');
         if (p == string::npos)
         {
            path = ".";
         }
         else
         {
            path = path.substr(0, p);
            orig = orig.substr(p + 1, orig.length() - p);
         }

         // as this is a wildcard, list all files in the current dir, choose those matched ones
         vector<SNode> curr_fl;
         if (LocalFS::list_dir(path, curr_fl) < 0)
            return -1;

         for (vector<SNode>::iterator s = curr_fl.begin(); s != curr_fl.end(); ++ s)
         {
            // skip "." and ".."
            if ((s->m_strName == ".") || (s->m_strName == ".."))
               continue;

            if (WildCard::match(orig, s->m_strName))
            {
               if (path == ".")
                  getFileList(s->m_strName, fl);
               else
                  getFileList(path + "/" + s->m_strName, fl);
            }
         }
      }

      // upload all files in the file list
      for (vector<string>::const_iterator i = fl.begin(); i != fl.end(); ++ i)
      {
         // process directory name change: /src/mydata -> /dst/mydata
         string dst = *i;
         if (prefix.length() > 0)
            dst.replace(0, prefix.length(), dstdir + "/");
         else
            dst = dstdir + "/" + dst;

         SNode s;
         if (LocalFS::stat(*i, s) < 0)
            continue;

         if (s.m_bIsDir)
            client.mkdir(dst);
         else
         {
   
            int result = upload(i->c_str(), dst.c_str(), client, replica_num, ip, cluster, encryption, smart);
            if ((result == SectorError::E_CONNECTION) ||
                (result == SectorError::E_BROKENPIPE))
            {
               // connection fail, retry once.
               result = upload(i->c_str(), dst.c_str(), client, replica_num, ip, cluster, encryption, smart);
            }
 
            if (result < 0)
            {
               // failed, remove the file in Sector.
               client.remove(dst);
               success = false;
               Utility::logout(client);
               return -1;
            }
         }
      }
   }

   Utility::logout(client);
   return success ? 0 : -1;
}
开发者ID:deniskin82,项目名称:sector-sphere,代码行数:101,代码来源:upload.cpp

示例4: main


//.........这里部分代码省略.........

   if (client.init(s.m_ClientConf.m_strMasterIP, s.m_ClientConf.m_iMasterPort) < 0)
      return -1;
   if (client.login(s.m_ClientConf.m_strUserName, s.m_ClientConf.m_strPassword, s.m_ClientConf.m_strCertificate.c_str()) < 0)
      return -1;


   vector<string> fl;
   bool wc = WildCard::isWildCard(argv[1]);
   if (!wc)
   {
      struct stat64 st;
      if (stat64(argv[1], &st) < 0)
      {
         cout << "ERROR: source file does not exist.\n";
         return -1;
      }
      getFileList(argv[1], fl);
   }
   else
   {
      string path = argv[1];
      string orig = path;
      size_t p = path.rfind('/');
      if (p == string::npos)
         path = "/";
      else
      {
         path = path.substr(0, p);
         orig = orig.substr(p + 1, orig.length() - p);
      }

      dirent **namelist;
      int n = scandir(path.c_str(), &namelist, 0, alphasort);

      if (n < 0)
         return -1;

      for (int i = 0; i < n; ++ i)
      {
         // skip "." and ".." and hidden directory
         if (namelist[i]->d_name[0] == '.')
         {
            free(namelist[i]);
            continue;
         }

         if (WildCard::match(orig, namelist[i]->d_name))
            getFileList(path + "/" + namelist[i]->d_name, fl);
      }
   }


   string olddir;
   for (int i = strlen(argv[1]) - 1; i >= 0; -- i)
   {
      if (argv[1][i] != '/')
      {
         olddir = string(argv[1]).substr(0, i);
         break;
      }
   }
   size_t p = olddir.rfind('/');
   if (p == string::npos)
      olddir = "";
   else
      olddir = olddir.substr(0, p);

   string newdir = argv[2];
   SNode attr;
   int r = client.stat(newdir, attr);
   if ((r < 0) || (!attr.m_bIsDir))
   {
      cout << "destination directory on Sector does not exist.\n";
      return -1;
   }

   for (vector<string>::const_iterator i = fl.begin(); i != fl.end(); ++ i)
   {
      string dst = *i;
      if (olddir.length() > 0)
         dst.replace(0, olddir.length(), newdir);
      else
         dst = newdir + "/" + dst;

      struct stat64 s;
      if (stat64(i->c_str(), &s) < 0)
         continue;

      if (S_ISDIR(s.st_mode))
         client.mkdir(dst);
      else
         upload(i->c_str(), dst.c_str(), client);
   }

   client.logout();
   client.close();

   return 1;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:101,代码来源:upload.cpp

示例5: main


//.........这里部分代码省略.........
#endif
      bool wc = WildCard::isWildCard(path.c_str());
      if (!wc)
      {
         struct stat st;
         if (stat(argv[i], &st) < 0)
         {
            cerr << "ERROR: source file does not exist.\n";
            return -1;
         }
         getFileList(argv[i], fl);
      }
      else
      {
         string path = argv[i];
#ifdef WIN32
         win_to_unix_path (path);
#endif
         string orig = path;
         size_t p = path.rfind('/');
         if (p == string::npos)
         {
            path = ".";
         }
         else
         {
            path = path.substr(0, p);
            orig = orig.substr(p + 1, orig.length() - p);
         }

         dirent **namelist;
         int n = scandir(path.c_str(), &namelist, 0, alphasort);

         if (n < 0)
            return -1;

         for (int i = 0; i < n; ++ i)
         {
            // skip "." and ".." and hidden directory
            if (namelist[i]->d_name[0] == '.')
            {
               free(namelist[i]);
               continue;
            }

            if (WildCard::match(orig, namelist[i]->d_name))
            {
               if (path == ".")
                  getFileList(namelist[i]->d_name, fl);
               else
                  getFileList(path + "/" + namelist[i]->d_name, fl);
            }
         }
      }

      string olddir;
      string input_path = argv[1];
#ifdef WIN32
      win_to_unix_path (input_path);
#endif
      for (int j = input_path.length() - 1; j >= 0; -- j)
      {
         if (input_path[j] != '/')
         {
            olddir = input_path.substr(0, j);
            break;
         }
      }
      size_t p = olddir.rfind('/');
      if (p == string::npos)
         olddir = "";
      else
         olddir = olddir.substr(0, p);

      for (vector<string>::const_iterator i = fl.begin(); i != fl.end(); ++ i)
      {
         string dst = *i;
         if (olddir.length() > 0)
            dst.replace(0, olddir.length(), newdir);
         else
            dst = newdir + "/" + dst;

         struct stat s;
         if (stat(i->c_str(), &s) < 0)
            continue;

         if (S_ISDIR(s.st_mode))
            client.mkdir(dst);
         else
         {
            if (upload(i->c_str(), dst.c_str(), client) < 0)
               success = false;
         }
      }
   }

   Utility::logout(client);

   return success ? 0 : -1;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:101,代码来源:upload.cpp


注:本文中的Sector::mkdir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。