From 115bd51f3fbbc4bf7a415c743237a453c634d104 Mon Sep 17 00:00:00 2001 From: Tianlong Wu Date: Fri, 22 Apr 2016 14:49:37 +0800 Subject: [PATCH 1/2] Fix a bug of truncating empty file --- src/curl.cpp | 4 ++-- test/integration-test-main.sh | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index 7e6304e..0a50fed 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -2595,7 +2595,7 @@ int S3fsCurl::PreGetObjectRequest(const char* tpath, int fd, off_t start, ssize_ { S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%zd]", SAFESTRPTR(tpath), (intmax_t)start, size); - if(!tpath || -1 == fd || 0 > start || 0 >= size){ + if(!tpath || -1 == fd || 0 > start || 0 > size){ return -1; } @@ -2611,7 +2611,7 @@ int S3fsCurl::PreGetObjectRequest(const char* tpath, int fd, off_t start, ssize_ requestHeaders = NULL; responseHeaders.clear(); - if(-1 != start && -1 != size){ + if(-1 != start && 0 < size){ string range = "bytes="; range += str(start); range += "-"; diff --git a/test/integration-test-main.sh b/test/integration-test-main.sh index 4cfdc27..43f426c 100755 --- a/test/integration-test-main.sh +++ b/test/integration-test-main.sh @@ -41,6 +41,24 @@ function test_truncate_file { rm_test_file } +function test_truncate_empty_file { + echo "Testing truncate empty file ..." + # Write an empty test file + touch ${TEST_TEXT_FILE} + + # Truncate the file to 1024 length + t_size=1024 + truncate ${TEST_TEXT_FILE} -s $t_size + + # Verify file is zero length + size=$(stat -c %s ${TEST_TEXT_FILE}) + if [ $t_size -ne $size ] + then + echo "error: expected ${TEST_TEXT_FILE} to be $t_size length, got $size" + exit 1 + fi + rm_test_file +} function test_mv_file { describe "Testing mv file function ..." @@ -377,6 +395,7 @@ function test_write_after_seek_ahead { function add_all_tests { add_tests test_append_file add_tests test_truncate_file + add_tests test_truncate_empty_file add_tests test_mv_file add_tests test_mv_directory add_tests test_redirects From cf23dc78ab5983c3dcca0a308cd3528e61118b46 Mon Sep 17 00:00:00 2001 From: Tianlong Wu Date: Fri, 22 Apr 2016 16:24:26 +0800 Subject: [PATCH 2/2] Use 'return' instead of 'exit' in test --- test/integration-test-main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration-test-main.sh b/test/integration-test-main.sh index 43f426c..693d5fc 100755 --- a/test/integration-test-main.sh +++ b/test/integration-test-main.sh @@ -55,7 +55,7 @@ function test_truncate_empty_file { if [ $t_size -ne $size ] then echo "error: expected ${TEST_TEXT_FILE} to be $t_size length, got $size" - exit 1 + return 1 fi rm_test_file }