Skip to content

Commit

Permalink
fix for issue #22
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed May 14, 2024
1 parent 720a95f commit a1f4331
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/de/gmuth/ipp/client/CupsClient.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.gmuth.ipp.client

/**
* Copyright (c) 2020-2023 Gerhard Muth
* Copyright (c) 2020-2024 Gerhard Muth
*/

import de.gmuth.ipp.client.IppExchangeException.ClientErrorNotFoundException
Expand Down Expand Up @@ -32,7 +32,7 @@ class CupsClient(

private val cupsServer =
IppPrinter(cupsUri, ippClient = ippClient, getPrinterAttributesOnInit = false)
.apply { workDirectory = cupsClientWorkDirectory.createDirectoryIfNotExists() }
.apply { workDirectory = cupsClientWorkDirectory.createDirectoryIfNotExists(false) }

init {
if (cupsUri.scheme == "ipps") config.trustAnyCertificateAndSSLHostname()
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.gmuth.ipp.client

/**
* Copyright (c) 2020-2023 Gerhard Muth
* Copyright (c) 2020-2024 Gerhard Muth
*/

import de.gmuth.ipp.attributes.*
Expand Down Expand Up @@ -582,6 +582,9 @@ class IppPrinter(
fun printerDirectory(printerName: String = name.text.replace("\\s+".toRegex(), "_")): File =
File(workDirectory, printerName).createDirectoryIfNotExists()

internal fun File.createDirectoryIfNotExists() = this
.apply { if (!mkdirs() && !isDirectory) throw IOException("Failed to create directory: $path") }
internal fun File.createDirectoryIfNotExists(throwOnFailure: Boolean = true) = this.apply {
if (!mkdirs() && !isDirectory) "Failed to create directory: $path".let {
if (throwOnFailure) throw IOException(it) else logger.warning(it)
}
}
}

0 comments on commit a1f4331

Please sign in to comment.