本文整理汇总了C++中Sector::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ Sector::remove方法的具体用法?C++ Sector::remove怎么用?C++ Sector::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sector
的用法示例。
在下文中一共展示了Sector::remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}