-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix FileHandle.truncateFile() #1297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Remove useless lseek() which would cause the function to fail.
Thanks for your contribution! Can we improve the tests in this area at the same time? |
@swift-ci please test |
@DagAgren The change looks fine, but can you write some tests that exercise the new functionality, and verify it works as expected? |
@DagAgren are you able to add the tests to verify your changes work as expected please? |
Sorry, I don't have an actual setup to build the code. I made this change quickly through github when I noticed the code was wrong while looking it up. |
@ianpartridge would you be able to add a test for this so that we can get it merged in? |
I'll have a go, yes. |
@ianpartridge did you manage to get anywhere with tests for this, or should we just merge as is? |
@alblue @ianpartridge @DagAgren I created some basic tests for this change but noticed that the fix does not work the same as the Darwin implementation. I had to change it like this: Should I create a new PR with this implementation? |
@nevil The behavior of your implementation more closely matches that of Darwin's, which is documented thusly:
The only real bug in the original implementation of this method is that it expects a return value of exactly 0 from |
@kperryua Should I go ahead and create a new PR with the updated implementation? |
@nevil Yes, please do. |
#1532 has been merged so I think this PR can be closed. |
FileHandle.truncateFile() currently does not work. It attempts to do a lseek() to the requested file size, which is not required before calling ftruncate. Furthermore, it expects this call to lseek() to return 0, which only happens if truncateFile() is called with a 0 size. Thus, the function will only succeed if called to truncate the file to zero bytes. In other cases, it will silently fail.