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


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

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


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

示例1: getFileList

int getFileList(const string& path, vector<string>& fl, Sector& client, unsigned int thresh)
{
   SNode attr;
   if (client.stat(path.c_str(), attr) < 0)
      return -1;

   if (attr.m_bIsDir)
   {
      vector<SNode> subdir;
      client.list(path, subdir);

      for (vector<SNode>::iterator i = subdir.begin(); i != subdir.end(); ++ i)
      {
         if (i->m_bIsDir)
            getFileList(path + "/" + i->m_strName, fl, client, thresh);
         else if ((i->m_sLocation.size() < thresh) && (int(i->m_sLocation.size()) < i->m_iReplicaNum))
            fl.push_back(path + "/" + i->m_strName);
      }
   }
   else if ((attr.m_sLocation.size() < thresh) && (int(attr.m_sLocation.size()) < attr.m_iReplicaNum))
   {
      fl.push_back(path);
   }

   return fl.size();
}
开发者ID:deniskin82,项目名称:sector-sphere,代码行数:26,代码来源:replicate.cpp

示例2: getFileList

int getFileList(const string& path, vector<string>& fl, Sector& client)
{
   SNode attr;
   if (client.stat(path, attr) < 0)
      return -1;

   fl.push_back(path);

   if (attr.m_bIsDir)
   {
      vector<SNode> subdir;
      client.list(path, subdir);

      for (vector<SNode>::iterator i = subdir.begin(); i != subdir.end(); ++ i)
      {
         if (i->m_bIsDir)
            getFileList(path + "/" + i->m_strName, fl, client);
         else
            fl.push_back(path + "/" + i->m_strName);
      }
   }

   return fl.size();
}
开发者ID:deniskin82,项目名称:sector-sphere,代码行数:24,代码来源:download.cpp

示例3: main

int main(int argc, char** argv)
{
   if (argc < 2)
   {
      help();
      return -1;
   }

   unsigned int thresh = 65536;
   int timeout = 3600 * 24; // default wait for one day

   CmdLineParser clp;
   if (clp.parse(argc, argv) < 0)
   {
      help();
      return -1;
   }

   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "w")
         thresh = atoi(i->second.c_str());
      else if (i->first == "t")
      {
         timeout = atoi(i->second.c_str());
         if (timeout < 0)
            timeout = INT_MAX;
      }
      else
      {
         help();
         return -1;
      }
   }

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

   list<string> filelist;

   for (vector<string>::iterator i = clp.m_vParams.begin(); i < clp.m_vParams.end(); ++ i)
   {
      vector<string> fl;
      fl.clear();

      bool wc = WildCard::isWildCard(*i);
      if (!wc)
      {
         SNode attr;
         if (client.stat(*i, attr) < 0)
         {
            cerr << "ERROR: source file does not exist.\n";
            return -1;
         }
         getFileList(*i, fl, client, thresh);
      }
      else
      {
         string path = *i;
         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);
         }

         vector<SNode> filelist;
         int r = client.list(path, filelist);
         if (r < 0)
            cerr << "ERROR: " << r << " " << SectorError::getErrorMsg(r) << endl;

         for (vector<SNode>::iterator i = filelist.begin(); i != filelist.end(); ++ i)
         {
            if (WildCard::match(orig, i->m_strName))
               getFileList(path + "/" + i->m_strName, fl, client, thresh);
         }
      }

      filelist.insert(filelist.end(), fl.begin(), fl.end());
   }

   int result = -1;

   timeval t;
   gettimeofday(&t, NULL);
   int exp_time = t.tv_sec + timeout;

   int interval = 1;
   int total = -1;
   int new_total = 0;

   while (!filelist.empty())
   {
      new_total = 0;

      for (list<string>::iterator i = filelist.begin(); i != filelist.end();)
//.........这里部分代码省略.........
开发者ID:deniskin82,项目名称:sector-sphere,代码行数:101,代码来源:replicate.cpp

示例4: main

int main(int argc, char** argv)
{
   logger::config( "/tmp", "sector-download" );

   for( int arg = 0; arg < argc; ++arg )
      log().debug << argv[ arg ] << ' ';
   log().debug << std::endl;

   if (argc < 3)
   {
      help(argv[0]);
      log().error << "Invalid command-line syntax, exiting with rc = -1" << std::endl;
      return -1;
   }

   CmdLineParser clp;
   if (clp.parse(argc, argv) < 0)
   {
      help(argv[0]);
      log().error << "Invalid command-line syntax, exiting with rc = -1" << std::endl;
      return -1;
   }

   if (clp.m_vParams.size() < 2)
   {
      help(argv[0]);
      log().error << "Invalid command-line syntax, exiting with rc = -1" << std::endl;
      return -1;
   }

   bool encryption = false;
   bool resume = false;

   for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
   {
      if (*i == "e")
         encryption = true;
      else if( *i == "smart" )
         resume = true;
      else
      {
         help(argv[0]);
         log().error << "Invalid command-line syntax, exiting with rc = -1" << std::endl;
         return -1;
      }
   }

   string newdir = *clp.m_vParams.rbegin();
   clp.m_vParams.erase(clp.m_vParams.begin() + clp.m_vParams.size() - 1);

   // check destination directory, which must exist
   SNode s;
   int r = LocalFS::stat(newdir, s);
   if ((r < 0) || !s.m_bIsDir)
   {
      cerr << "ERROR: destination directory does not exist.\n";
      log().error << "stat failed on destination directory, err = " << r << ", exiting with rc = -1" << std::endl;
      return -1;
   }

   // login to SectorFS
   Sector client;
   int rc = Utility::login(client);
   if (rc < 0)
   {
      cerr << "ERROR: failed to log in to sector\n";
      log().error << "Client login to master failed with err = " << rc << ", exiting with rc = -1" << std::endl;
      return -1;
   }

   // start downloading all files
   for (vector<string>::iterator i = clp.m_vParams.begin(); i != clp.m_vParams.end(); ++ i)
   {
      vector<string> fl;
      bool wc = WildCard::isWildCard(*i);
      if (!wc)
      {
         SNode attr;
         if ((rc = client.stat(*i, attr)) < 0)
         {
            cerr << "ERROR: source file does not exist.\n";
            log().error << "Failed to stat sector file " << *i << ", err = " << rc << std::endl;
            return -1;
         }
         getFileList(*i, fl, client);
      }
      else
      {
         string path = *i;
         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);
         }

         vector<SNode> filelist;
//.........这里部分代码省略.........
开发者ID:deniskin82,项目名称:sector-sphere,代码行数:101,代码来源:download.cpp

示例5: main

int main(int argc, char** argv)
{
   if (argc != 2)
   {
      cout << "USAGE: rm <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;

   string path = argv[1];
   bool wc = WildCard::isWildCard(path);

   if (!wc)
   {
      int r = client.remove(path);

      if (r == SectorError::E_NOEMPTY)
      {
         if (isRecursive(path))
            client.rmr(path);
      }
      else if (r < 0)
         cout << "ERROR: " << r << " " << SectorError::getErrorMsg(r) << endl;
   }
   else
   {
      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);
      }

      vector<SNode> filelist;
      int r = client.list(path, filelist);
      if (r < 0)
         cout << "ERROR: " << r << " " << SectorError::getErrorMsg(r) << endl;

      bool recursive = false;

      vector<string> filtered;
      for (vector<SNode>::iterator i = filelist.begin(); i != filelist.end(); ++ i)
      {
         if (WildCard::match(orig, i->m_strName))
         {
            if (recursive)
               client.rmr(path + "/" + i->m_strName);
            else
            {
               r = client.remove(path + "/" + i->m_strName);

               if (r == SectorError::E_NOEMPTY)
               {
                  recursive = isRecursive(path + "/" + i->m_strName);
                  if (recursive)
                     client.rmr(path + "/" + i->m_strName);
               }
               else if (r < 0)
                  cout << "ERROR: " << r << " " << SectorError::getErrorMsg(r) << endl;
            }
         }
      }
   }

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

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


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