Merge pull request #379 from ggtakec/master

Fixed a bug about writing sparsed file - #375
This commit is contained in:
Takeshi Nakatani 2016-03-22 15:06:31 +09:00
commit 91861e7fcd

View File

@ -728,6 +728,29 @@ int FdEntity::Open(headers_t* pmeta, ssize_t size, time_t time)
if(-1 != fd){ if(-1 != fd){
// already opened, needs to increment refcnt. // already opened, needs to increment refcnt.
Dup(); Dup();
// check only file size(do not need to save cfs and time.
if(0 <= size && pagelist.Size() != static_cast<size_t>(size)){
// truncate temporary file size
if(-1 == ftruncate(fd, static_cast<size_t>(size))){
S3FS_PRN_ERR("failed to truncate temporary file(%d) by errno(%d).", fd, errno);
return -EIO;
}
// resize page list
if(!pagelist.Resize(static_cast<size_t>(size), false)){
S3FS_PRN_ERR("failed to truncate temporary file information(%d).", fd);
return -EIO;
}
}
// set original headers and set size.
size_t new_size = (0 <= size ? static_cast<size_t>(size) : 0);
if(pmeta){
orgmeta = *pmeta;
new_size = static_cast<size_t>(get_size(orgmeta));
}
if(new_size < size_orgmeta){
size_orgmeta = new_size;
}
return 0; return 0;
} }
@ -1057,8 +1080,12 @@ int FdEntity::Load(off_t start, size_t size)
} }
}else{ }else{
// single request // single request
if(0 < need_load_size){
S3fsCurl s3fscurl; S3fsCurl s3fscurl;
result = s3fscurl.GetObjectRequest(path.c_str(), fd, (*iter)->offset, need_load_size); result = s3fscurl.GetObjectRequest(path.c_str(), fd, (*iter)->offset, need_load_size);
}else{
result = 0;
}
} }
if(0 != result){ if(0 != result){
break; break;
@ -1498,6 +1525,17 @@ ssize_t FdEntity::Write(const char* bytes, off_t start, size_t size)
} }
AutoLock auto_lock(&fdent_lock); AutoLock auto_lock(&fdent_lock);
// check file size
if(pagelist.Size() < static_cast<size_t>(start)){
// grow file size
if(-1 == ftruncate(fd, static_cast<size_t>(start))){
S3FS_PRN_ERR("failed to truncate temporary file(%d).", fd);
return -EIO;
}
// add new area
pagelist.SetPageLoadedStatus(static_cast<off_t>(pagelist.Size()), static_cast<size_t>(start) - pagelist.Size(), false);
}
int result; int result;
ssize_t wsize; ssize_t wsize;