xref: /aosp_15_r20/external/okio/okio-testing-support/src/nonWasmMain/kotlin/okio/TestingNonWasm.kt (revision f9742813c14b702d71392179818a9e591da8620c)
1  /*
2   * Copyright (C) 2023 Square, Inc.
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *      http://www.apache.org/licenses/LICENSE-2.0
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package okio
17  
18  import okio.fakefilesystem.FakeFileSystem
19  
20  actual typealias Clock = kotlinx.datetime.Clock
21  
22  actual typealias Instant = kotlinx.datetime.Instant
23  
fromEpochSecondsnull24  actual fun fromEpochSeconds(
25    epochSeconds: Long,
26  ) = Instant.fromEpochSeconds(epochSeconds)
27  
28  actual fun fromEpochMilliseconds(
29    epochMilliseconds: Long,
30  ) = Instant.fromEpochMilliseconds(epochMilliseconds)
31  
32  actual val FileSystem.isFakeFileSystem: Boolean
33    get() = this is FakeFileSystem
34  
35  actual val FileSystem.allowSymlinks: Boolean
36    get() = (this as? FakeFileSystem)?.allowSymlinks == true
37  
38  actual val FileSystem.allowReadsWhileWriting: Boolean
39    get() = (this as? FakeFileSystem)?.allowReadsWhileWriting == true
40  
41  actual var FileSystem.workingDirectory: Path
42    get() {
43      return when (this) {
44        is FakeFileSystem -> workingDirectory
45        is ForwardingFileSystem -> delegate.workingDirectory
46        else -> error("cannot get working directory: $this")
47      }
48    }
49    set(value) {
50      when (this) {
51        is FakeFileSystem -> workingDirectory = value
52        is ForwardingFileSystem -> delegate.workingDirectory = value
53        else -> error("cannot set working directory: $this")
54      }
55    }
56