Skip to content

Commit 41bcf25

Browse files
authored
Merge pull request #11 from Archinamon/fix_abs_path
calculating abs path only once on init step
2 parents 411ac39 + bb342a8 commit 41bcf25

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.github/workflows/check-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jobs:
2323
- uses: fwilhe2/setup-kotlin@main
2424
with:
2525
install-native: true
26+
27+
- name: Select Xcode 14
28+
if: ${{ startsWith(matrix.os, 'macos') }}
29+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app/Contents/Developer
2630

2731
- name: Cache Build files
2832
uses: actions/cache@v2

.github/workflows/gradle-publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jobs:
3434
restore-keys: |
3535
${{ runner.os }}-gradle-
3636
37+
- name: Select Xcode 14
38+
if: ${{ startsWith(matrix.os, 'macos') }}
39+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app/Contents/Developer
40+
3741
- name: Build with Gradle [Macos]
3842
uses: eskatos/gradle-command-action@v1
3943
if: ${{ startsWith(matrix.os, 'macos') }}

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
~/.konan
2626
~/.gradle
2727
key: ${{ runner.os }}-${{ hashFiles('gradle.properties') }}
28+
- name: Select Xcode 14
29+
if: ${{ startsWith(matrix.os, 'macos') }}
30+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app/Contents/Developer
2831
- uses: eskatos/gradle-command-action@v1
2932
name: Test Windows Target
3033
if: ${{ startsWith(matrix.os, 'windows') }}

src/posixMain/kotlin/File.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ actual class File actual constructor(
5151
private val modeAppend = "a"
5252
private val modeRewrite = "w"
5353

54+
private val absPath: String
55+
56+
init {
57+
// not lazy but preserve on obj init
58+
absPath = getRealAbsolutePath()
59+
}
60+
5461
actual fun getParent(): String? {
5562
val path = getAbsolutePath()
5663
val idx = path.lastIndexOf(filePathSeparator)
@@ -76,6 +83,14 @@ actual class File actual constructor(
7683
actual fun getPath(): String = pathname
7784

7885
actual fun getAbsolutePath(): String {
86+
if (absPath.isNotBlank()) {
87+
return absPath
88+
}
89+
90+
return getRealAbsolutePath()
91+
}
92+
93+
private fun getRealAbsolutePath(): String {
7994
return memScoped {
8095
val path = if (pathname.first() != filePathSeparator || pathname.first() == '.') {
8196
getcwd(allocArray(FILENAME_MAX), FILENAME_MAX.convert())
@@ -309,7 +324,7 @@ actual fun File.readBytes(): ByteArray {
309324
}
310325

311326
actual fun File.writeBytes(bytes: ByteArray) {
312-
// no need to use pinning or memscope, cause it's inside the method already does
327+
// no need to use pinning or memscope, 'cause it's inside the method already does
313328
writeBytes(bytes, O_RDWR, bytes.size.convert(), Byte.SIZE_BYTES.convert())
314329
}
315330

0 commit comments

Comments
 (0)