Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend filesystem support #213

Merged
merged 42 commits into from
Sep 13, 2023
Merged

Extend filesystem support #213

merged 42 commits into from
Sep 13, 2023

Conversation

fzhinkin
Copy link
Collaborator

@fzhinkin fzhinkin commented Aug 17, 2023

This PR is not about bringing full filesystems support, but it rather adds few functions to make life easier.

The change adds basic path processing functions to Path:

  • parent to get the parent path, backed by dirname on most platforms
  • name to get the file/directory name, backed by basename on most platforms
  • isAbsolute to check if the path is relative or absolute.

Paths, unlike in Okio, are platform dependent, so a/b\\c.txt has different meaning on Windows and Linux.

PR also brings few functions to work with filesystem. The design is driven by Okio's FileSystem, but functionality are not even close to it.
Supported functionality:

  • delete file (or empty directory)
  • mkdirs
  • check file existence
  • get file metadata (limited to isDirectory/isFile for now)
  • atomic move

kotilnx.io.files package remains experimental (even compared to the whole library not being stable yet).

Closes: #206 #211 #212 #183 #214

Copy link
Contributor

@jeffdgr8 jeffdgr8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few doc comment fix suggestions. Looking forward to the next release with these features.

Also, if you feel inclined to fix, I noticed utilApple.kt got an extra redundant ExperimentalForeignApi OptIn added:

@file:OptIn(UnsafeNumber::class, ExperimentalForeignApi::class, ExperimentalForeignApi::class)

core/jvm/src/files/FileSystemJvm.kt Outdated Show resolved Hide resolved
core/jvm/src/files/FileSystemJvm.kt Outdated Show resolved Hide resolved
core/build.gradle.kts Outdated Show resolved Hide resolved
core/common/src/files/FileSystem.kt Outdated Show resolved Hide resolved
core/common/src/files/Paths.kt Outdated Show resolved Hide resolved
core/common/src/files/Paths.kt Outdated Show resolved Hide resolved
core/common/src/files/Paths.kt Outdated Show resolved Hide resolved
core/common/src/files/Paths.kt Outdated Show resolved Hide resolved
@fzhinkin fzhinkin linked an issue Aug 23, 2023 that may be closed by this pull request
Copy link
Contributor

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Please also update README overview/links

core/common/src/files/FileSystem.kt Show resolved Hide resolved
core/common/src/files/FileSystem.kt Outdated Show resolved Hide resolved
core/common/src/files/FileSystem.kt Outdated Show resolved Hide resolved
core/common/src/files/FileSystem.kt Show resolved Hide resolved
core/common/src/files/FileSystem.kt Show resolved Hide resolved
core/common/src/files/FileSystem.kt Show resolved Hide resolved
core/common/test/files/SmokeFileTest.kt Show resolved Hide resolved
core/apple/test/NSInputStreamSourceTest.kt Show resolved Hide resolved
* @throws kotlinx.io.IOException when [path] already exists and [mustCreate] is `true`.
* @throws kotlinx.io.IOException when the creation of one of the directories fails.
*/
public fun createDirectories(path: Path, mustCreate: Boolean = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if mustCreate=false, an entity on such a path already existed, but it was a file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to abstain from reporting an error in that case as the path already exists. Not sure if we need to be more strict about what this path is actually pointing to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, I want to create /a/b/c directories, but there is already a /a/b/c file in the file system and at the same time the mustCreate=false flag.
On the one hand, we cannot throw path already exists error, on the other hand, I call the function of creating directories. It turns out that an error has occurred, but I will receive a message about it postponed when I try to create a new file /a/b/c/my.txt (this is often whatcreateDirectories is called for)

This comment was marked as resolved.

core/common/src/files/FileSystem.kt Outdated Show resolved Hide resolved
core/common/src/files/FileSystem.kt Show resolved Hide resolved
core/common/src/files/Paths.kt Outdated Show resolved Hide resolved
Copy link
Contributor

@whyoleg whyoleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
Some minor comments. The only major thing for me is naming of FileSytem.read/write methods

core/apple/src/files/FileSystemApple.kt Outdated Show resolved Hide resolved
core/apple/src/files/FileSystemApple.kt Outdated Show resolved Hide resolved
core/common/src/files/FileSystem.kt Outdated Show resolved Hide resolved
core/common/src/files/Paths.kt Show resolved Hide resolved
core/js/src/files/FileSystemJs.kt Outdated Show resolved Hide resolved
core/jvm/src/files/FileSystemJvm.kt Outdated Show resolved Hide resolved
core/native/src/files/FileSystemNative.kt Outdated Show resolved Hide resolved
core/native/src/files/PathsNative.kt Outdated Show resolved Hide resolved
core/unix/src/files/FileSystemUnix.kt Outdated Show resolved Hide resolved
core/common/test/util.kt Show resolved Hide resolved
Copy link
Contributor

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Have a few more or less minor comments and it's good to go

import kotlinx.io.RawSource

/**
* An interface providing basic operations on a filesystem.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to enrich the top-level documentation in the follow up PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @throws kotlinx.io.IOException when [path] already exists and [mustCreate] is `true`.
* @throws kotlinx.io.IOException when the creation of one of the directories fails.
*/
public fun createDirectories(path: Path, mustCreate: Boolean = false)

This comment was marked as resolved.

core/common/src/files/FileSystem.kt Outdated Show resolved Hide resolved
core/common/src/files/Paths.kt Show resolved Hide resolved
core/common/src/files/Paths.kt Show resolved Hide resolved
@fzhinkin fzhinkin merged commit e421c04 into develop Sep 13, 2023
1 check passed
@fzhinkin fzhinkin deleted the extend-filesystem-support branch October 12, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants