[GH-ISSUE #290] File opened with O_TRUNC is not flushed #150

Closed
opened 2026-03-04 01:42:38 +03:00 by kerem · 3 comments
Owner

Originally created by @RobbKistler on GitHub (Nov 4, 2015).
Original GitHub issue: https://github.com/s3fs-fuse/s3fs-fuse/issues/290

s3fs-fuse @ ad2a406205

Scenerio:
Open an existing file, non-empty file O_TRUNC and close it (no writes),

Expected results:
File with zero length. (Verified on local ext4 filesystem)

Actual results:
The file still contains original content.

Originally created by @RobbKistler on GitHub (Nov 4, 2015). Original GitHub issue: https://github.com/s3fs-fuse/s3fs-fuse/issues/290 s3fs-fuse @ ad2a4062058db3ebed85dd4d350221e177ab31fe _Scenerio:_ Open an existing file, non-empty file O_TRUNC and close it (no writes), _Expected results:_ File with zero length. (Verified on local ext4 filesystem) _Actual results:_ The file still contains original content.
kerem closed this issue 2026-03-04 01:42:38 +03:00
Author
Owner

@RobbKistler commented on GitHub (Nov 4, 2015):

Created PR with repro test and potential fix.

<!-- gh-comment-id:153589741 --> @RobbKistler commented on GitHub (Nov 4, 2015): Created PR with repro test and potential fix.
Author
Owner

@ggtakec commented on GitHub (Nov 8, 2015):

@RobbKistler Thanks for your fixed codes.

I made a few changes to your correction.
Only when the file size is needed to change, s3fs calls RowFlush function.

When the open function is called with O_TRUNC, the file size is set Zero as soon as possible.
So it means that s3fs calls REST api(upload zero size object) when calling open with O_TRUNC.
Then you are correct about calls flush, but it does not need evey time.
My changes after your cahnages, If the file size is zero, s3fs does not call flush.

Please check it.
Thanks in advance for your help.

<!-- gh-comment-id:154776387 --> @ggtakec commented on GitHub (Nov 8, 2015): @RobbKistler Thanks for your fixed codes. I made a few changes to your correction. Only when the file size is needed to change, s3fs calls RowFlush function. When the open function is called with O_TRUNC, the file size is set Zero as soon as possible. So it means that s3fs calls REST api(upload zero size object) when calling open with O_TRUNC. Then you are correct about calls flush, but it does not need evey time. My changes after your cahnages, If the file size is zero, s3fs does not call flush. Please check it. Thanks in advance for your help.
Author
Owner

@RobbKistler commented on GitHub (Nov 9, 2015):

Look great! Thank you.

<!-- gh-comment-id:155160399 --> @RobbKistler commented on GitHub (Nov 9, 2015): Look great! Thank you.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/s3fs-fuse#150
No description provided.