From dd7d9268f20c0dd915e87b94f71836a9f286d288 Mon Sep 17 00:00:00 2001 From: Robb Kistler Date: Tue, 3 Nov 2015 22:04:16 -0800 Subject: [PATCH] Force flush in s3fs_open() if file is truncated. --- src/s3fs.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 7ef5244..16c9025 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -2002,6 +2002,7 @@ static int s3fs_open(const char* path, struct fuse_file_info* fi) { int result; struct stat st; + bool needs_flush = false; S3FS_PRN_INFO("[path=%s][flags=%d]", path, fi->flags); @@ -2026,6 +2027,7 @@ static int s3fs_open(const char* path, struct fuse_file_info* fi) if((unsigned int)fi->flags & O_TRUNC){ st.st_size = 0; + needs_flush = true; } if(!S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)){ st.st_mtime = -1; @@ -2037,6 +2039,15 @@ static int s3fs_open(const char* path, struct fuse_file_info* fi) if(NULL == (ent = FdManager::get()->Open(path, &meta, static_cast(st.st_size), st.st_mtime, false, true))){ return -EIO; } + + if (needs_flush){ + if(0 != (result = ent->RowFlush(path, true))){ + S3FS_PRN_ERR("could not upload file(%s): result=%d", path, result); + FdManager::get()->Close(ent); + return result; + } + } + fi->fh = ent->GetFd(); S3FS_MALLOCTRIM(0);