Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,20 @@ abstract class AbstractFileSystemTest(
}
}

@Test fun fileHandleResizeToZero() {
val path = base / "file-handle-resize-to-zero"
fileSystem.openReadWrite(path).use { handle ->

handle.sink().buffer().use { sink ->
sink.writeUtf8("abcde")
}

handle.resize(0L)

assertEquals(0L, handle.size())
}
}

@Test fun fileHandleResizeLarger() {
val path = base / "file-handle-resize-larger"
fileSystem.openReadWrite(path).use { handle ->
Expand Down
4 changes: 3 additions & 1 deletion okio/src/mingwX64Main/kotlin/okio/WindowsFileHandle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import platform.windows.FlushFileBuffers
import platform.windows.GetFileSizeEx
import platform.windows.GetLastError
import platform.windows.HANDLE
import platform.windows.INVALID_SET_FILE_POINTER
import platform.windows.LARGE_INTEGER
import platform.windows.NO_ERROR
import platform.windows.ReadFile
import platform.windows.SetEndOfFile
import platform.windows.SetFilePointer
Expand Down Expand Up @@ -146,7 +148,7 @@ internal class WindowsFileHandle(
lpDistanceToMoveHigh = distanceToMoveHigh.ptr,
dwMoveMethod = FILE_BEGIN.toUInt(),
)
if (movePointerResult == 0U) {
if (movePointerResult == INVALID_SET_FILE_POINTER && GetLastError().toInt() != NO_ERROR) {
throw lastErrorToIOException()
}
if (SetEndOfFile(file) == 0) {
Expand Down