bug fixed: file_offset has no effect when use trunk file

pull/56/merge
yuqing 2017-04-28 11:11:38 +08:00
parent e16ef61c7e
commit 5e23bd9144
2 changed files with 32 additions and 31 deletions

View File

@ -1,4 +1,7 @@
Version 5.11 2017-04-28
* bug fixed: file_offset has no effect when use trunk file
Version 5.10 2017-03-29 Version 5.10 2017-03-29
* use fc_safe_read instead of read, and fc_safe_write instead of write * use fc_safe_read instead of read, and fc_safe_write instead of write
you must upgrade libfastcommon to V1.35 or later you must upgrade libfastcommon to V1.35 or later

View File

@ -255,41 +255,39 @@ int dio_open_file(StorageFileContext *pFileContext)
{ {
int result; int result;
if (pFileContext->fd >= 0)
{
return 0;
}
pFileContext->fd = open(pFileContext->filename,
pFileContext->open_flags, 0644);
if (pFileContext->fd < 0) if (pFileContext->fd < 0)
{ {
result = errno != 0 ? errno : EACCES; pFileContext->fd = open(pFileContext->filename,
logError("file: "__FILE__", line: %d, " \ pFileContext->open_flags, 0644);
"open file: %s fail, " \ if (pFileContext->fd < 0)
"errno: %d, error info: %s", \ {
__LINE__, pFileContext->filename, \ result = errno != 0 ? errno : EACCES;
result, STRERROR(result)); logError("file: "__FILE__", line: %d, " \
} "open file: %s fail, " \
else "errno: %d, error info: %s", \
{ __LINE__, pFileContext->filename, \
result = 0; result, STRERROR(result));
} }
else
{
result = 0;
}
pthread_mutex_lock(&g_dio_thread_lock); pthread_mutex_lock(&g_dio_thread_lock);
g_storage_stat.total_file_open_count++; g_storage_stat.total_file_open_count++;
if (result == 0) if (result == 0)
{ {
g_storage_stat.success_file_open_count++; g_storage_stat.success_file_open_count++;
} }
pthread_mutex_unlock(&g_dio_thread_lock); pthread_mutex_unlock(&g_dio_thread_lock);
if (result != 0) if (result != 0)
{ {
return result; return result;
} }
}
if (pFileContext->offset > 0 && lseek(pFileContext->fd, \ if (pFileContext->offset > 0 && lseek(pFileContext->fd,
pFileContext->offset, SEEK_SET) < 0) pFileContext->offset, SEEK_SET) < 0)
{ {
result = errno != 0 ? errno : EIO; result = errno != 0 ? errno : EIO;