Fixed issue: 320(++)

1) Changes calling fread/fwrite logic(Issue: 320)
    In conjunction with this issue, the opened file discripter is rewinded after reading/writing.
    The put_local_fd() and get_localfd() function always returns rewinded fd.





git-svn-id: http://s3fs.googlecode.com/svn/trunk@412 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
ggtakec@gmail.com 2013-04-17 06:39:02 +00:00
parent a92a4c0a4f
commit eaf43e6f59

View File

@ -428,8 +428,15 @@ static int get_local_fd(const char* path) {
fd = fileno(tmpfile());
}
if(fd == -1)
if(fd == -1){
YIKES(-errno);
}
// seek to head of file.
if(0 != lseek(fd, 0, SEEK_SET)){
SYSLOGERR("line %d: lseek: %d", __LINE__, -errno);
FGPRINT(" get_local_fd - lseek error(%d)\n", -errno);
return -errno;
}
FILE *f = fdopen(fd, "w+");
if(f == 0){
@ -456,8 +463,8 @@ static int get_local_fd(const char* path) {
curl_easy_setopt(curl, CURLOPT_URL, my_url.c_str());
result = my_curl_easy_perform(curl, NULL, NULL, f);
destroy_curl_handle(curl);
if(result != 0) {
destroy_curl_handle(curl);
fclose(f);
return -result;
}
@ -466,9 +473,6 @@ static int get_local_fd(const char* path) {
fflush(f);
fsync(fd);
if(fd == -1)
YIKES(-errno);
if(S_ISREG(mode) && !S_ISLNK(mode)) {
// make the file's mtime match that of the file on s3
// if fd is tmpfile, but we force tor set mtime.
@ -482,8 +486,14 @@ static int get_local_fd(const char* path) {
YIKES(-errno);
}
}
// seek to head of file.
if(0 != lseek(fd, 0, SEEK_SET)){
SYSLOGERR("line %d: lseek: %d", __LINE__, -errno);
FGPRINT(" get_local_fd - lseek error(%d)\n", -errno);
return -errno;
}
}
destroy_curl_handle(curl);
return fd;
}
@ -915,6 +925,13 @@ static int put_local_fd(const char* path, headers_t meta, int fd) {
result = put_local_fd_small_file(path, meta, fd);
}
// seek to head of file.
if(0 != lseek(fd, 0, SEEK_SET)){
SYSLOGERR("line %d: lseek: %d", __LINE__, -errno);
FGPRINT(" put_local_fd - lseek error(%d)\n", -errno);
return -errno;
}
return result;
}