mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-22 16:58:55 +00:00
Allow truncation of open and modified files
Regression introduced in f5bf41cf11
.
Fixes #1575.
This commit is contained in:
parent
1838f52e19
commit
8a51a26819
@ -474,8 +474,11 @@ FdEntity* FdManager::Open(const char* path, headers_t* pmeta, off_t size, time_t
|
||||
ent = (*iter).second;
|
||||
ent->Dup();
|
||||
if(ent->IsModified()){
|
||||
// If the file is being modified, it will not be resized.
|
||||
size = -1;
|
||||
// If the file is being modified and it's size is larger than size parameter, it will not be resized.
|
||||
off_t cur_size = 0;
|
||||
if(ent->GetSize(cur_size) && size <= cur_size){
|
||||
size = -1;
|
||||
}
|
||||
}
|
||||
close = true;
|
||||
|
||||
|
@ -1404,7 +1404,7 @@ function test_ensurespace_move_file() {
|
||||
return 1
|
||||
fi
|
||||
if [ ${MOVED_FILE_LENGTH} -ne ${BIG_FILE_LENGTH} ]; then
|
||||
echo "Failed to move file with file length"
|
||||
echo "Failed to move file with file length: ${MOVED_FILE_LENGTH} ${BIG_FILE_LENGTH}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
@ -94,6 +94,18 @@ class OssfsUnitTest(unittest.TestCase):
|
||||
self.assertEqual(len(data1), len(data2))
|
||||
self.assertEqual(data1, data2)
|
||||
|
||||
def test_truncate_open_file(self):
|
||||
filename = "%s" % (self.random_string(10))
|
||||
fd = os.open(filename, os.O_CREAT|os.O_RDWR)
|
||||
try:
|
||||
os.write(fd, 'a' * 42)
|
||||
self.assertEqual(os.fstat(fd).st_size, 42)
|
||||
os.ftruncate(fd, 100)
|
||||
self.assertEqual(os.fstat(fd).st_size, 100)
|
||||
finally:
|
||||
os.close(fd)
|
||||
self.assertEqual(100, os.stat(filename).st_size)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user