Skip to content

Commit

Permalink
Rename Filesystem to FileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Jan 4, 2021
1 parent d364ec8 commit 2ec05f1
Show file tree
Hide file tree
Showing 36 changed files with 405 additions and 407 deletions.
2 changes: 1 addition & 1 deletion android-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Then run the tests:
Or just a single test:

```
./gradlew :android-test:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=okio.SystemFilesystemTest
./gradlew :android-test:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=okio.SystemFileSystemTest
```


Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ Sending and receiving data over the network is a bit like writing and reading
files. We use `BufferedSink` to encode output and `BufferedSource` to decode
input. Like files, network protocols can be text, binary, or a mix of both. But
there are also some substantial differences between the network and the
filesystem.
file system.

With a file you’re either reading or writing but with the network you can do
both! Some protocols handle this by taking turns: write a request, read a
Expand Down
2 changes: 1 addition & 1 deletion docs/multiplatform.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Timeout is on all platforms, but only the JVM has a useful implementation.
Available on all platforms.


### Filesystem
### File System

Available on all platforms. For JavaScript this requires [Node.js][node_js].

Expand Down
2 changes: 1 addition & 1 deletion okio-fakefilesystem/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
POM_ARTIFACT_ID=okio-fakefilesystem
POM_NAME=Okio Fake Filesystem
POM_NAME=Okio Fake File System
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,40 @@ import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import okio.Buffer
import okio.ByteString
import okio.ExperimentalFilesystem
import okio.ExperimentalFileSystem
import okio.FileMetadata
import okio.FileNotFoundException
import okio.Filesystem
import okio.FileSystem
import okio.IOException
import okio.Path
import okio.Path.Companion.toPath
import okio.Sink
import okio.Source
import okio.Timeout
import okio.fakefilesystem.FakeFilesystem.Element.Directory
import okio.fakefilesystem.FakeFilesystem.Element.File
import okio.fakefilesystem.FakeFileSystem.Element.Directory
import okio.fakefilesystem.FakeFileSystem.Element.File
import kotlin.jvm.JvmField
import kotlin.jvm.JvmName

/**
* A fully in-memory filesystem useful for testing. It includes features to support writing
* A fully in-memory file system useful for testing. It includes features to support writing
* better tests.
*
* Use [openPaths] to see which paths have been opened for read or write, but not yet closed. Tests
* should call [checkNoOpenFiles] in `tearDown()` to confirm that no file streams were leaked.
*
* By default this filesystem permits deletion and removal of open files. Configure
* By default this file system permits deletion and removal of open files. Configure
* [windowsLimitations] to true to throw an [IOException] when asked to delete or rename an open
* file.
*/
@ExperimentalFilesystem
class FakeFilesystem(
@ExperimentalFileSystem
class FakeFileSystem(
private val windowsLimitations: Boolean = false,
private val workingDirectory: Path = (if (windowsLimitations) "F:\\".toPath() else "/".toPath()),

@JvmField
val clock: Clock = Clock.System
) : Filesystem() {
) : FileSystem() {

init {
require(workingDirectory.isAbsolute) {
Expand All @@ -67,7 +67,7 @@ class FakeFilesystem(
private val openFiles = mutableListOf<OpenFile>()

/**
* Canonical paths for every file and directory in this filesystem. This omits filesystem roots
* Canonical paths for every file and directory in this file system. This omits file system roots
* like `C:\` and `/`.
*/
@get:JvmName("allPaths")
Expand Down Expand Up @@ -96,11 +96,11 @@ class FakeFilesystem(
get() = openFiles.map { it.canonicalPath }

/**
* Confirm that all files that have been opened on this filesystem (with [source], [sink], and
* Confirm that all files that have been opened on this file system (with [source], [sink], and
* [appendingSink]) have since been closed. Call this in your test's `tearDown()` function to
* confirm that your program hasn't leaked any open files.
*
* Forgetting to close a file on a real filesystem is a severe error that may lead to a program
* Forgetting to close a file on a real file system is a severe error that may lead to a program
* crash. The operating system enforces a limit on how many files may be open simultaneously. On
* Linux this is [getrlimit] and is commonly adjusted with the `ulimit` command.
*
Expand Down Expand Up @@ -260,7 +260,7 @@ class FakeFilesystem(
}

/**
* Gets the directory at [path], creating it if [path] is a filesystem root.
* Gets the directory at [path], creating it if [path] is a file system root.
*
* @throws IOException if the named directory is not a root and does not exist, or if it does
* exist but is not a directory.
Expand Down Expand Up @@ -387,5 +387,5 @@ class FakeFilesystem(
override fun toString() = "sink(${openFile.canonicalPath})"
}

override fun toString() = "FakeFilesystem"
override fun toString() = "FakeFileSystem"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package okio.fakefilesystem

import kotlinx.datetime.Instant
import okio.ExperimentalFilesystem
import okio.ExperimentalFileSystem
import okio.FileMetadata
import kotlin.jvm.JvmName

@JvmName("newFileMetadata")
@ExperimentalFilesystem
@ExperimentalFileSystem
internal fun FileMetadata(
isRegularFile: Boolean = false,
isDirectory: Boolean = false,
Expand Down
4 changes: 2 additions & 2 deletions okio/src/appleMain/kotlin/okio/posixVariant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import platform.posix.S_IFREG
import platform.posix.errno
import platform.posix.stat

@ExperimentalFilesystem
internal actual fun PosixSystemFilesystem.variantMetadataOrNull(path: Path): FileMetadata? {
@ExperimentalFileSystem
internal actual fun PosixFileSystem.variantMetadataOrNull(path: Path): FileMetadata? {
return memScoped {
val stat = alloc<stat>()
if (platform.posix.lstat(path.toString(), stat.ptr) != 0) {
Expand Down
6 changes: 3 additions & 3 deletions okio/src/commonMain/kotlin/okio/-Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package okio

@ExperimentalFilesystem
internal expect val PLATFORM_FILESYSTEM: Filesystem
@ExperimentalFileSystem
internal expect val PLATFORM_FILE_SYSTEM: FileSystem

@ExperimentalFilesystem
@ExperimentalFileSystem
internal expect val PLATFORM_TEMPORARY_DIRECTORY: Path

internal expect val DIRECTORY_SEPARATOR: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlin.annotation.AnnotationTarget.CLASS
import kotlin.annotation.AnnotationTarget.FUNCTION
import kotlin.annotation.AnnotationTarget.PROPERTY

@RequiresOptIn(level = ERROR, message = "okio's Filesystem is unstable and subject to change")
@RequiresOptIn(level = ERROR, message = "okio's FileSystem is unstable and subject to change")
@Retention(BINARY)
@Target(CLASS, FUNCTION, PROPERTY)
annotation class ExperimentalFilesystem
annotation class ExperimentalFileSystem
30 changes: 15 additions & 15 deletions okio/src/commonMain/kotlin/okio/FileMetadata.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package okio
/**
* Description of a file or another object referenced by a path.
*
* In simple use a filesystem is a mechanism for organizing files and directories on a local storage
* device. In practice filesystems are more capable and their contents more varied. For example, a
* path may refer to:
* In simple use a file system is a mechanism for organizing files and directories on a local
* storage device. In practice file systems are more capable and their contents more varied. For
* example, a path may refer to:
*
* * An operating system process that consumes data, produces data, or both. For example, reading
* from the `/dev/urandom` file on Linux returns a unique sequence of pseudorandom bytes to each
Expand All @@ -31,25 +31,25 @@ package okio
* size of a pipe is not well defined: the writer can write as much data as the reader is able to
* read.
*
* * A file on a remote filesystem. The performance and availability of remote files may be quite
* * A file on a remote file system. The performance and availability of remote files may be quite
* different from that of local files!
*
* * A symbolic link (symlink) to another path. When attempting to access this path the filesystem
* * A symbolic link (symlink) to another path. When attempting to access this path the file system
* will follow the link and return data from the target path.
*
* * The same content as another path without a symlink. On UNIX filesystems an inode is an
* * The same content as another path without a symlink. On UNIX file systems an inode is an
* anonymous handle to a file's content, and multiple paths may target the same inode without any
* other relationship to one another. A consequence of this design is that a directory with three
* 1 GiB files may only need 1 GiB on the storage device.
*
* This class does not attempt to model these rich filesystem features! It exposes a limited view
* useful for programs with only basic filesystem needs. Be cautious of the potential consequences
* of special files when writing programs that operate on a filesystem.
* This class does not attempt to model these rich file system features! It exposes a limited view
* useful for programs with only basic file system needs. Be cautious of the potential consequences
* of special files when writing programs that operate on a file system.
*
* File metadata is subject to change, and code that operates on filesystems should defend against
* File metadata is subject to change, and code that operates on file systems should defend against
* changes to the file that occur between reading metadata and subsequent operations.
*/
@ExperimentalFilesystem
@ExperimentalFileSystem
class FileMetadata(
/** True if this file is a container of bytes. If this is true, then [size] is non-null. */
val isRegularFile: Boolean,
Expand All @@ -60,14 +60,14 @@ class FileMetadata(
/**
* Returns the number of bytes readable from this file. The amount of storage resources consumed
* by this file may be larger (due to block size overhead, redundant copies for RAID, etc.), or
* smaller (due to filesystem compression, shared inodes, etc).
* smaller (due to file system compression, shared inodes, etc).
*/
val size: Long?,

/**
* Returns the system time of the host computer when this file was created, if the host filesystem
* supports this feature. This is typically available on Windows NTFS filesystems and not
* available on UNIX or Windows FAT filesystems.
* Returns the system time of the host computer when this file was created, if the host file
* system supports this feature. This is typically available on Windows NTFS file systems and not
* available on UNIX or Windows FAT file systems.
*/
val createdAtMillis: Long?,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@
*/
package okio

import okio.Filesystem.Companion.SYSTEM
import okio.FileSystem.Companion.SYSTEM
import kotlin.jvm.JvmField

/**
* Read and write access to a hierarchical collection of files, addressed by [paths][Path]. This
* is a natural interface to the [current computer's local filesystem][SYSTEM].
* is a natural interface to the [current computer's local file system][SYSTEM].
*
* Not Just the Local Filesystem
* -----------------------------
* Not Just the Local File System
* ------------------------------
*
* Other implementations are possible:
*
* * `FakeFilesystem` is an in-memory filesystem suitable for testing. Note that this class is
* * `FakeFileSystem` is an in-memory file system suitable for testing. Note that this class is
* included in the `okio-fakefilesystem` artifact.
*
* * A ZIP filesystem could provide access to the contents of a `.zip` file.
* * A ZIP file system could provide access to the contents of a `.zip` file.
*
* * A remote filesystem could access files over the network.
* * A remote file system could access files over the network.
*
* * A [decorating filesystem][ForwardingFilesystem] could apply monitoring, encryption,
* compression, or filtering to another filesystem implementation.
* * A [decorating file system][ForwardingFileSystem] could apply monitoring, encryption,
* compression, or filtering to another file system implementation.
*
* For improved capability and testability, consider structuring your classes to dependency inject
* a `Filesystem` rather than using [SYSTEM] directly.
* a `FileSystem` rather than using [SYSTEM] directly.
*
* Limited API
* -----------
*
* This interface is limited in which filesystem features it supports. Applications that need rich
* filesystem features should use another API, possibly alongside this API.
* This interface is limited in which file system features it supports. Applications that need rich
* file system features should use another API, possibly alongside this API.
*
* This class cannot create special file types like hard links, symlinks, pipes, or mounts. Reading
* or writing these files works as if they were regular files.
Expand All @@ -55,7 +55,7 @@ import kotlin.jvm.JvmField
*
* It cannot lock files, or query which files are locked.
*
* It cannot watch the filesystem for changes.
* It cannot watch the file system for changes.
*
* Multiplatform
* -------------
Expand All @@ -73,23 +73,21 @@ import kotlin.jvm.JvmField
* Differences vs. Java IO APIs
* ----------------------------
*
* The `java.io.File` class is Java's original filesystem API. The `delete` and `renameTo` methods
* The `java.io.File` class is Java's original file system API. The `delete` and `renameTo` methods
* return false if the operation failed. The `list` method returns null if the file isn't a
* directory or could not be listed. This class always throws `IOExceptions` when operations don't
* succeed.
*
* The `java.nio.Path` and `java.nio.Files` classes are the entry points of Java's new filesystem
* API. Each `Path` instance is scoped to a particular filesystem, though that is often implicit
* because the `Paths.get()` function automatically uses the default (ie. system) filesystem.
* In Okio's API paths are just identifiers; you must use a specific `Filesystem` object to do
* The `java.nio.Path` and `java.nio.Files` classes are the entry points of Java's new file system
* API. Each `Path` instance is scoped to a particular file system, though that is often implicit
* because the `Paths.get()` function automatically uses the default (ie. system) file system.
* In Okio's API paths are just identifiers; you must use a specific `FileSystem` object to do
* I/O with.
*
* [s3]: https://aws.amazon.com/s3/
*/
@ExperimentalFilesystem
abstract class Filesystem {
@ExperimentalFileSystem
abstract class FileSystem {
/**
* Resolves [path] against the current working directory and symlinks in this filesystem. The
* Resolves [path] against the current working directory and symlinks in this file system. The
* returned path identifies the same file as [path], but with an absolute path that does not
* include any symbolic links.
*
Expand Down Expand Up @@ -124,7 +122,7 @@ abstract class Filesystem {
abstract fun metadataOrNull(path: Path): FileMetadata?

/**
* Returns true if [path] identifies an object on this filesystem.
* Returns true if [path] identifies an object on this file system.
*
* @throws IOException if [path] cannot be accessed due to a connectivity problem, permissions
* problem, or other issue.
Expand Down Expand Up @@ -214,9 +212,9 @@ abstract class Filesystem {
* exists, it is first removed. If `source == target`, this operation does nothing. This may be
* used to move a file or a directory.
*
* **Only as Atomic as the Underlying Filesystem Supports**
* **Only as Atomic as the Underlying File System Supports**
*
* FAT and NTFS filesystems cannot atomically move a file over an existing file. If the target
* FAT and NTFS file systems cannot atomically move a file over an existing file. If the target
* file already exists, the move is performed into two steps:
*
* 1. Atomically delete the target file.
Expand All @@ -233,14 +231,14 @@ abstract class Filesystem {
* * This operation returns normally, the source file is absent, and the target file contains the
* data previously held by the source file. This is the success case.
*
* * The operation throws an [IOException] and the filesystem is unchanged. For example, this
* * The operation throws an [IOException] and the file system is unchanged. For example, this
* occurs if this process lacks permissions to perform the move.
*
* * This operation throws an [IOException], the target file is deleted, but the source file is
* unchanged. This is the partial failure case described above and is only possible on
* filesystems like FAT and NTFS that do not support atomic file replacement. Typically in such
* cases this operation won't return at all because the process or operating system has also
* crashed.
* file systems like FAT and NTFS that do not support atomic file replacement. Typically in
* such cases this operation won't return at all because the process or operating system has
* also crashed.
*
* There is no failure mode where the target file holds a subset of the bytes of the source file.
* If the rename step cannot be performed atomically, this function will throw an [IOException]
Expand Down Expand Up @@ -283,7 +281,7 @@ abstract class Filesystem {
*
* @throws IOException if there is nothing at [path] to delete, or if there is a file or directory
* but it could not be deleted. Deletes fail if the current process doesn't have access, if
* the filesystem is readonly, or if [path] is a non-empty directory. This list of potential
* the file system is readonly, or if [path] is a non-empty directory. This list of potential
* problems is not exhaustive.
*/
@Throws(IOException::class)
Expand Down Expand Up @@ -321,11 +319,11 @@ abstract class Filesystem {

companion object {
/**
* The current process's host filesystem. Use this instance directly, or dependency inject a
* [Filesystem] to make code testable.
* The current process's host file system. Use this instance directly, or dependency inject a
* [FileSystem] to make code testable.
*/
@JvmField
val SYSTEM: Filesystem = PLATFORM_FILESYSTEM
val SYSTEM: FileSystem = PLATFORM_FILE_SYSTEM

/**
* Returns a writable temporary directory on [SYSTEM].
Expand Down
Loading

0 comments on commit 2ec05f1

Please sign in to comment.