-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reduce github context read from env to mitigate "argument list t…
…oo long" bug (#43)
- Loading branch information
Showing
3 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.monta.slack.notifier.util | ||
|
||
import kotlinx.cinterop.ByteVar | ||
import kotlinx.cinterop.allocArray | ||
import kotlinx.cinterop.memScoped | ||
import kotlinx.cinterop.toKString | ||
import platform.posix.fclose | ||
import platform.posix.fgets | ||
import platform.posix.fopen | ||
|
||
fun readStringFromFile(filePath: String): String { | ||
val returnBuffer = StringBuilder() | ||
val file = fopen(filePath, "r") | ||
?: throw IllegalArgumentException("Cannot open file $filePath for reading") | ||
try { | ||
memScoped { | ||
val readBufferLength = 64 * 1024 | ||
val buffer = allocArray<ByteVar>(readBufferLength) | ||
var line = fgets(buffer, readBufferLength, file)?.toKString() | ||
while (line != null) { | ||
returnBuffer.append(line) | ||
line = fgets(buffer, readBufferLength, file)?.toKString() | ||
} | ||
} | ||
} finally { | ||
fclose(file) | ||
} | ||
return returnBuffer.toString() | ||
} |