mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-22 08:48:55 +00:00
Use std::string::compare and operator== where possible (#2256)
This commit is contained in:
parent
56a4e67009
commit
e157d811cb
@ -192,7 +192,7 @@ bool AdditionalHeader::AddHeader(headers_t& meta, const char* path) const
|
||||
}else{
|
||||
// directly comparing
|
||||
if(paddhead->basestring.length() < pathlength){
|
||||
if(paddhead->basestring.empty() || 0 == strcmp(&path[pathlength - paddhead->basestring.length()], paddhead->basestring.c_str())){
|
||||
if(paddhead->basestring.empty() || paddhead->basestring == &path[pathlength - paddhead->basestring.length()]){
|
||||
// match -> adding header
|
||||
meta[paddhead->headkey] = paddhead->headvalue;
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* met
|
||||
std::string tag = lower(hiter->first);
|
||||
if(tag == "etag"){
|
||||
stretag = hiter->second;
|
||||
if('\0' != petag[0] && 0 != strcmp(petag, stretag.c_str())){
|
||||
if('\0' != petag[0] && petag != stretag){
|
||||
is_delete_cache = true;
|
||||
}
|
||||
break;
|
||||
|
@ -454,7 +454,7 @@ FdManager::~FdManager()
|
||||
if(this == FdManager::get()){
|
||||
for(fdent_map_t::iterator iter = fent.begin(); fent.end() != iter; ++iter){
|
||||
FdEntity* ent = (*iter).second;
|
||||
S3FS_PRN_WARN("To exit with the cache file opened: path=%s, refcnt=%d", ent->GetPath(), ent->GetOpenCount());
|
||||
S3FS_PRN_WARN("To exit with the cache file opened: path=%s, refcnt=%d", ent->GetPath().c_str(), ent->GetOpenCount());
|
||||
delete ent;
|
||||
}
|
||||
fent.clear();
|
||||
@ -508,7 +508,7 @@ FdEntity* FdManager::GetFdEntity(const char* path, int& existfd, bool newfd, Aut
|
||||
for(iter = fent.begin(); iter != fent.end(); ++iter){
|
||||
if(iter->second && iter->second->FindPseudoFd(existfd)){
|
||||
// found opened fd in map
|
||||
if(0 == strcmp(iter->second->GetPath(), path)){
|
||||
if(iter->second->GetPath() == path){
|
||||
if(newfd){
|
||||
existfd = iter->second->Dup(existfd);
|
||||
}
|
||||
@ -525,7 +525,7 @@ FdEntity* FdManager::GetFdEntity(const char* path, int& existfd, bool newfd, Aut
|
||||
// when the file is opened.
|
||||
if(!FdManager::IsCacheDir()){
|
||||
for(iter = fent.begin(); iter != fent.end(); ++iter){
|
||||
if(iter->second && iter->second->IsOpen() && 0 == strcmp(iter->second->GetPath(), path)){
|
||||
if(iter->second && iter->second->IsOpen() && iter->second->GetPath() == path){
|
||||
return iter->second;
|
||||
}
|
||||
}
|
||||
@ -552,7 +552,7 @@ FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off
|
||||
// search a entity in all which opened the temporary file.
|
||||
//
|
||||
for(iter = fent.begin(); iter != fent.end(); ++iter){
|
||||
if(iter->second && iter->second->IsOpen() && 0 == strcmp(iter->second->GetPath(), path)){
|
||||
if(iter->second && iter->second->IsOpen() && iter->second->GetPath() == path){
|
||||
break; // found opened fd in mapping
|
||||
}
|
||||
}
|
||||
@ -669,7 +669,7 @@ int FdManager::GetPseudoFdCount(const char* path)
|
||||
|
||||
// search from all entity.
|
||||
for(fdent_map_t::iterator iter = fent.begin(); iter != fent.end(); ++iter){
|
||||
if(iter->second && 0 == strcmp(iter->second->GetPath(), path)){
|
||||
if(iter->second && iter->second->GetPath() == path){
|
||||
// found the entity for the path
|
||||
return iter->second->GetOpenCount();
|
||||
}
|
||||
@ -690,7 +690,7 @@ void FdManager::Rename(const std::string &from, const std::string &to)
|
||||
// search a entity in all which opened the temporary file.
|
||||
//
|
||||
for(iter = fent.begin(); iter != fent.end(); ++iter){
|
||||
if(iter->second && iter->second->IsOpen() && 0 == strcmp(iter->second->GetPath(), from.c_str())){
|
||||
if(iter->second && iter->second->IsOpen() && iter->second->GetPath() == from){
|
||||
break; // found opened fd in mapping
|
||||
}
|
||||
}
|
||||
@ -719,7 +719,7 @@ void FdManager::Rename(const std::string &from, const std::string &to)
|
||||
|
||||
bool FdManager::Close(FdEntity* ent, int fd)
|
||||
{
|
||||
S3FS_PRN_DBG("[ent->file=%s][pseudo_fd=%d]", ent ? ent->GetPath() : "", fd);
|
||||
S3FS_PRN_DBG("[ent->file=%s][pseudo_fd=%d]", ent ? ent->GetPath().c_str() : "", fd);
|
||||
|
||||
if(!ent || -1 == fd){
|
||||
return true; // returns success
|
||||
|
@ -111,7 +111,7 @@ class FdEntity
|
||||
int Dup(int fd, AutoLock::Type locktype = AutoLock::NONE);
|
||||
int OpenPseudoFd(int flags = O_RDONLY, AutoLock::Type locktype = AutoLock::NONE);
|
||||
int GetOpenCount(AutoLock::Type locktype = AutoLock::NONE) const;
|
||||
const char* GetPath() const { return path.c_str(); }
|
||||
const std::string& GetPath() const { return path; }
|
||||
bool RenamePath(const std::string& newpath, std::string& fentmapkey);
|
||||
int GetPhysicalFd() const { return physical_fd; }
|
||||
bool IsModified() const;
|
||||
|
@ -198,12 +198,12 @@ bool S3ObjList::GetLastName(std::string& lastname) const
|
||||
lastname = "";
|
||||
for(s3obj_t::const_iterator iter = objects.begin(); iter != objects.end(); ++iter){
|
||||
if((*iter).second.orgname.length()){
|
||||
if(0 > strcmp(lastname.c_str(), (*iter).second.orgname.c_str())){
|
||||
if(lastname.compare(iter->second.orgname) < 0){
|
||||
lastname = (*iter).second.orgname;
|
||||
result = true;
|
||||
}
|
||||
}else{
|
||||
if(0 > strcmp(lastname.c_str(), (*iter).second.normalname.c_str())){
|
||||
if(lastname.compare(iter->second.normalname) < 0){
|
||||
lastname = (*iter).second.normalname;
|
||||
result = true;
|
||||
}
|
||||
|
@ -217,18 +217,18 @@ int main(int argc, char** argv)
|
||||
struct stat st;
|
||||
if(0 == stat(fiter->c_str(), &st)){
|
||||
if(!S_ISREG(st.st_mode)){
|
||||
std::cerr << "[ERROR] File " << fiter->c_str() << " is existed, but it is not regular file." << std::endl;
|
||||
std::cerr << "[ERROR] File " << *fiter << " is existed, but it is not regular file." << std::endl;
|
||||
free(pData);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(-1 == (fd = open(fiter->c_str(), O_WRONLY))){
|
||||
std::cerr << "[ERROR] Could not open " << fiter->c_str() << std::endl;
|
||||
std::cerr << "[ERROR] Could not open " << *fiter << std::endl;
|
||||
free(pData);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}else{
|
||||
if(-1 == (fd = open(fiter->c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644))){
|
||||
std::cerr << "[ERROR] Could not create " << fiter->c_str() << std::endl;
|
||||
std::cerr << "[ERROR] Could not create " << *fiter << std::endl;
|
||||
free(pData);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -240,7 +240,7 @@ int main(int argc, char** argv)
|
||||
for(ssize_t writepos = 0, writecnt = 0; writepos < piter->size; writepos += writecnt){
|
||||
if(-1 == (writecnt = pwrite(fd, &(pData[writepos]), static_cast<size_t>(piter->size - writepos), (piter->start + writepos)))){
|
||||
if(EAGAIN != errno && EWOULDBLOCK != errno && EINTR != errno){
|
||||
std::cerr << "[ERROR] Failed writing to " << fiter->c_str() << " by errno : " << errno << std::endl;
|
||||
std::cerr << "[ERROR] Failed writing to " << *fiter << " by errno : " << errno << std::endl;
|
||||
close(fd);
|
||||
free(pData);
|
||||
exit(EXIT_FAILURE);
|
||||
|
Loading…
Reference in New Issue
Block a user