Skip to content

SystemFileSystem.sink does not create empty file on NodeJs target #251

@vdshb

Description

@vdshb

Reproducer (works correctly on jvm and linuxX64 but fails on jsNode):

package tests

import kotlinx.io.files.Path
import kotlinx.io.files.SystemFileSystem
import kotlin.test.Test
import kotlin.test.assertTrue

class ReproducerTest {

    @Test
    fun test() {
        // GIVEN
        val testFileDirPath = "/tmp/test-0001"
        val testFilePath = testFileDirPath + "/test-file.txt"

        SystemFileSystem.createDirectories(Path(testFileDirPath), false)
        assertTrue { isDirExist(testFileDirPath) }

        // WHEN creating empty file
        SystemFileSystem.sink(Path(testFilePath)).close()

        // THEN
        assertTrue { isFileExist(testFilePath) }

        // CLEANING
        SystemFileSystem.delete(Path(testFilePath), false)
    }

    fun isDirExist(directoryPath: String): Boolean {
        return SystemFileSystem.metadataOrNull(Path(directoryPath))?.isDirectory ?: false
    }

    fun isFileExist(filePath: String): Boolean {
        return SystemFileSystem.metadataOrNull(Path(filePath))?.isRegularFile ?: false
    }

}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions