Fixed a bug about mtime - #299

This commit is contained in:
Takeshi Nakatani 2015-11-29 15:53:53 +00:00
parent 8ffff5ba96
commit 7b62de80f6
3 changed files with 17 additions and 17 deletions

View File

@ -802,17 +802,6 @@ int FdEntity::Open(headers_t* pmeta, ssize_t size, time_t time)
}
}
// set mtime
if(-1 != time){
if(0 != SetMtime(time)){
S3FS_PRN_ERR("failed to set mtime. errno(%d)", errno);
fclose(pfile);
pfile = NULL;
fd = -1;
return (0 == errno ? -EIO : -errno);
}
}
// reset cache stat file
if(need_save_csf){
CacheFileStat cfstat(path.c_str());
@ -834,6 +823,17 @@ int FdEntity::Open(headers_t* pmeta, ssize_t size, time_t time)
size_orgmeta = 0;
}
// set mtime(set "x-amz-meta-mtime" in orgmeta)
if(-1 != time){
if(0 != SetMtime(time)){
S3FS_PRN_ERR("failed to set mtime. errno(%d)", errno);
fclose(pfile);
pfile = NULL;
fd = -1;
return (0 == errno ? -EIO : -errno);
}
}
return 0;
}
@ -1846,19 +1846,19 @@ FdEntity* FdManager::Open(const char* path, headers_t* pmeta, ssize_t size, time
return ent;
}
FdEntity* FdManager::ExistOpen(const char* path, int existfd)
FdEntity* FdManager::ExistOpen(const char* path, int existfd, bool ignore_existfd)
{
S3FS_PRN_DBG("[path=%s][fd=%d]", SAFESTRPTR(path), existfd);
S3FS_PRN_DBG("[path=%s][fd=%d][ignore_existfd=%s]", SAFESTRPTR(path), existfd, ignore_existfd ? "true" : "false");
// search by real path
FdEntity* ent = Open(path, NULL, -1, -1, false, false);
if(!ent && -1 != existfd){
if(!ent && (ignore_existfd || (-1 != existfd))){
// search from all fdentity because of not using cache.
AutoLock auto_lock(&FdManager::fd_manager_lock);
for(fdent_map_t::iterator iter = fent.begin(); iter != fent.end(); ++iter){
if((*iter).second && (*iter).second->GetFd() == existfd && (*iter).second->IsOpen()){
if((*iter).second && (*iter).second->IsOpen() && (ignore_existfd || ((*iter).second->GetFd() == existfd))){
// found opend fd in map
if(0 == strcmp((*iter).second->GetPath(), path)){
ent = (*iter).second;

View File

@ -212,7 +212,7 @@ class FdManager
FdEntity* GetFdEntity(const char* path, int existfd = -1);
FdEntity* Open(const char* path, headers_t* pmeta = NULL, ssize_t size = -1, time_t time = -1, bool force_tmpfile = false, bool is_create = true);
FdEntity* ExistOpen(const char* path, int existfd = -1);
FdEntity* ExistOpen(const char* path, int existfd = -1, bool ignore_existfd = false);
void Rename(const std::string &from, const std::string &to);
bool Close(FdEntity* ent);
bool ChangeEntityToTempPath(FdEntity* ent, const char* path);

View File

@ -774,7 +774,7 @@ static int put_headers(const char* path, headers_t& meta, bool is_copy)
}
FdEntity* ent = NULL;
if(NULL == (ent = FdManager::get()->ExistOpen(path))){
if(NULL == (ent = FdManager::get()->ExistOpen(path, -1, !(FdManager::get()->IsCacheDir())))){
// no opened fd
if(FdManager::get()->IsCacheDir()){
// create cache file if be needed