override fun createTempFile()

in plugin-dotnet-agent/src/main/kotlin/jetbrains/buildServer/dotnet/coverage/utils/TempFactoryImpl.kt [13:36]


    override fun createTempFile(path: File,
                                prefix: String,
                                extension: String,
                                maxAttempts: Int): File {
        _fileService.createDirectory(path)
        var sequenceValue = ""
        var attempts = maxAttempts
        do {
            val fileName = _fileService.sanitizeFileName(prefix + sequenceValue) + extension
            val file = File(path, fileName)
            if (!_fileService.exists(file) && !_fileService.isDirectory(file)) {
                try {
                    if (_fileService.createFile(file)) {
                        return file
                    }
                } catch (e: IOException) {
                    if (attempts-- < 0) {
                        throw IOException("Error creating temporary file '" + file + "' (multiple attempts): " + e.message, e)
                    }
                }
            }
            sequenceValue = _sequencer.nextFrom(sequenceValue)
        } while (true)
    }