diff --git a/okio-testing-support/src/commonMain/kotlin/okio/AbstractFileSystemTest.kt b/okio-testing-support/src/commonMain/kotlin/okio/AbstractFileSystemTest.kt index 9ed87c3b64..2609852811 100644 --- a/okio-testing-support/src/commonMain/kotlin/okio/AbstractFileSystemTest.kt +++ b/okio-testing-support/src/commonMain/kotlin/okio/AbstractFileSystemTest.kt @@ -42,6 +42,7 @@ abstract class AbstractFileSystemTest( val windowsLimitations: Boolean, val allowClobberingEmptyDirectories: Boolean, val allowAtomicMoveFromFileToDirectory: Boolean, + val allowRenameWhenTargetIsOpen: Boolean = !windowsLimitations, temporaryDirectory: Path, ) { val base: Path = temporaryDirectory / "${this::class.simpleName}-${randomToken(16)}" @@ -1501,10 +1502,15 @@ abstract class AbstractFileSystemTest( val to = base / "to.txt" from.writeUtf8("source file") to.writeUtf8("target file") - expectIOExceptionOnWindows { + + val expectCrash = !allowRenameWhenTargetIsOpen + try { fileSystem.source(to).use { fileSystem.atomicMove(from, to) } + assertFalse(expectCrash) + } catch (_: IOException) { + assertTrue(expectCrash) } } diff --git a/okio/src/jvmTest/kotlin/okio/FileHandleFileSystemTest.kt b/okio/src/jvmTest/kotlin/okio/FileHandleFileSystemTest.kt index 9a41e37ff0..06baf8a060 100644 --- a/okio/src/jvmTest/kotlin/okio/FileHandleFileSystemTest.kt +++ b/okio/src/jvmTest/kotlin/okio/FileHandleFileSystemTest.kt @@ -17,8 +17,8 @@ package okio import com.google.common.jimfs.Configuration import com.google.common.jimfs.Jimfs +import java.nio.file.FileSystems import kotlinx.datetime.Clock -import okio.FileHandleFileSystemTest.FileHandleTestingFileSystem import okio.FileSystem.Companion.asOkioFileSystem /** @@ -73,3 +73,13 @@ class FileHandleNioFileSystemWrapperFileSystemTest : AbstractFileSystemTest( allowAtomicMoveFromFileToDirectory = true, temporaryDirectory = FileSystem.SYSTEM_TEMPORARY_DIRECTORY, ) + +class FileHandleNioDefaultFileSystemWrapperFileSystemTest : AbstractFileSystemTest( + clock = Clock.System, + fileSystem = FileSystems.getDefault().asOkioFileSystem(), + windowsLimitations = false, + allowClobberingEmptyDirectories = Path.DIRECTORY_SEPARATOR == "\\", + allowAtomicMoveFromFileToDirectory = false, + allowRenameWhenTargetIsOpen = Path.DIRECTORY_SEPARATOR != "\\", + temporaryDirectory = FileSystem.SYSTEM_TEMPORARY_DIRECTORY, +)