From a3ef5c820dde927dc416c69509e54f71e0643f6c Mon Sep 17 00:00:00 2001 From: Robb Kistler Date: Tue, 3 Nov 2015 21:47:15 -0800 Subject: [PATCH 1/2] Add file truncate test This test creates a file with contents, truncates it to zero and verifies that it is zero length. --- test/integration-test-main.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/integration-test-main.sh b/test/integration-test-main.sh index f920bc9..f03e22c 100755 --- a/test/integration-test-main.sh +++ b/test/integration-test-main.sh @@ -81,6 +81,24 @@ function test_append_file { rm_test_file } +function test_truncate_file { + echo "Testing truncate file ..." + # Write a small test file + echo "${TEST_TEXT}" > ${TEST_TEXT_FILE} + + # Truncate file to 0 length. This should trigger open(path, O_RDWR | O_TRUNC...) + : > ${TEST_TEXT_FILE} + + # Verify file is zero length + if [ -s ${TEST_TEXT_FILE} ] + then + echo "error: expected ${TEST_TEXT_FILE} to be zero length" + exit 1 + fi + rm_test_file +} + + function test_mv_file { echo "Testing mv file function ..." @@ -362,6 +380,7 @@ function test_extended_attributes { function run_all_tests { test_append_file + test_truncate_file test_mv_file test_mv_directory test_redirects From dd7d9268f20c0dd915e87b94f71836a9f286d288 Mon Sep 17 00:00:00 2001 From: Robb Kistler Date: Tue, 3 Nov 2015 22:04:16 -0800 Subject: [PATCH 2/2] 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);