mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-10 23:00:57 +00:00
Merge pull request #291 from RobbKistler/truncate
Issue #290: File opened with O_TRUNC is not flushed
This commit is contained in:
commit
331b8456a0
11
src/s3fs.cpp
11
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<ssize_t>(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);
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user