Commit Graph

34 Commits

Author SHA1 Message Date
Abduqodiri Qurbonzoda 91f0c3c342 Clarify copyToRecursively doc about symlinks #SDP-1816
This MR is the result of the security audit that was conducted for Path recursive functions:
https://youtrack.jetbrains.com/issue/SDP-1816/Security-issues-of-Path-recursive-functions-in-StdLib#focus=Comments-27-7269144.0-0
Eliminates confusions regarding symbolic links.

Merge-request: KT-MR-10245
Merged-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
2023-06-16 22:40:56 +00:00
Ilya Gorbunov f8d001c21f KT-57298 createParentDirectories: handle already existing directory symlink 2023-04-08 15:21:12 +00:00
Ilya Gorbunov d2dc23d8bb Introduce Path.createParentDirectories function #KT-53263 2023-02-27 20:36:21 +00:00
Abduqodiri Qurbonzoda 80b48eed0b Fix Path.copyToRecursively when copying across file systems #KT-55935
Merge-request: KT-MR-8705
Merged-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
2023-02-07 08:25:54 +00:00
Abduqodiri Qurbonzoda fff593492d Introduce Common AutoCloseable & use #KT-31066
Co-authored-by: Ilya Gorbunov <Ilya.Gorbunov@jetbrains.com>

Merge-request: KT-MR-8113
Merged-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
2022-12-27 11:50:22 +00:00
Abduqodiri Qurbonzoda 90189f9c39 Provide Path.copyToRecursively() and Path.deleteRecursively() #KT-52928 2022-09-18 22:49:01 +00:00
Abduqodiri Qurbonzoda 78666e3ecb Provide visit extension functions for java.nio.file.Path #KT-52910 2022-06-28 00:52:43 +00:00
Abduqodiri Qurbonzoda e7b37b3497 Implement a walk extension function for java.nio.file.Path #KT-52909 2022-06-28 00:52:42 +00:00
Ilya Gorbunov eba6a4a000 KT-44089 Reflect Android SDK version to determine whether platform implementatoins are eligible
SDK version sanity check, suppress all reflection errors, duplicate SDK reflection code for more robustness
2021-12-06 12:24:45 +03:00
Mikhail Glukhikh ffbd574a08 Use -opt-in instead of -Xopt-in in comments and scripts 2021-09-08 23:43:55 +03:00
Ilya Gorbunov 81f2aea316 Stabilize existing Path API and annotate with @Throws where appropriate
KT-45913
2021-04-06 14:24:42 +03:00
Ilya Gorbunov 0634351fbc Introduce pathString/absolute/absolutePathString
Rename invariantSeparatorsPath to invariantSeparatorsPathString
to have more consistent names of methods returning path strings.

KT-19192
2020-11-29 17:46:47 +03:00
Ilya Gorbunov 84f5a294f7 Allow passing null parent directory to createTempFile/Directory
null signifies the default temp directory.

KT-19192
2020-11-29 17:46:47 +03:00
Ilya Gorbunov 64d85f259c Relax writeText/appendText parameter type to CharSequence
KT-19192
2020-11-29 17:46:47 +03:00
Ilya Gorbunov 7fd96f5773 Fix annotation spelling in docs
KT-43586
2020-11-26 15:37:22 +03:00
Jake Wharton 3a693e112b Update ExperimentalPathApi annotation's SinceKotlin value to 1.4 2020-10-28 16:55:57 +03:00
Ilya Gorbunov fe098ec821 Revise functions in PathReadWrite
- Adjust implementations to avoid excessive vararg copies
- Remove options from forEachLine, it doesn't make much sense and
isn't consistent with the other read* functions.
- Revise inlineness of functions in PathReadWrite
- Compact implementations of those that are remained inline.
- Clarify docs of functions for reading the entire file

#KT-19192
2020-10-28 07:36:19 +03:00
Ilya Gorbunov a43cc0d1f9 Implement additional Path extensions
#KT-19192
2020-10-28 07:36:16 +03:00
Ilya Gorbunov 038f1cbd1e Add glob filtering when listing directory entries
#KT-19192
2020-10-28 07:36:14 +03:00
Ilya Gorbunov e7c888a2e6 Avoid introducing Path.printWriter
#KT-19192
2020-10-28 07:36:11 +03:00
Ilya Gorbunov 9f659d74df Introduce dedicated experimental annotation for Path extensions
#KT-19192
2020-10-28 07:36:08 +03:00
Ilya Gorbunov 997cd35e06 Move Path extensions to the new package kotlin.io.path
This avoids the conflict with the existing top-level functions in
kotlin.io package.

#KT-19192
2020-10-28 07:36:06 +03:00
Ilya Gorbunov 7d58a5e2f2 Simplify Path.copyTo implementation
Delegate most checks to the platform Files.copy.
This changes the exception type thrown in one case,
so document when it happens. Also 'copyTo' no longer
creates target parent directory if it doesn't exist.

#KT-19192
2020-10-28 07:36:02 +03:00
Ilya Gorbunov f6d2400208 Workaround bugs in Path.relativize
Also add actual paths to the relativeTo error message.

#KT-19192
2020-10-28 07:36:00 +03:00
AJ b3a87356bd Add java.nio.Path extensions to stdlib-jdk7: part 2
- Add notExists
- Rename isFile to isRegularFile
- Remove forEachBlock
- Rename listFiles
- Add relativeTo extensions
- Remove extra overloads
- Update doc comments
- Address review comments

#KT-19192
2020-10-28 07:35:57 +03:00
AJ 03cc0bf6aa Add java.nio.Path extensions to stdlib-jdk7
This PR adds most extensions on `java.io.File` in `kotlin.io` to `java.nio.Path`. This includes extensions from `FileReadWrite.kt`, `Utils.kt`, and `FileTreeWalk.kt`.

I attempted to keep the implementations, documentation, and tests as similar as possible to the existing implementations.

I am happy to add, remove, or move to separate PRs any of the functions of this PR.

### `File` extensions that were not added to `Path`

##### `createTempDir`, `createTempFile`

These functions have no `File` parameters, so can't be overloaded. Equivalents exist as `Files.createTempFile()` and `Files.createTempDirectory()`.

##### `startsWith`, `endsWith`, `normalize`, `resolve`, `resolveSibling`

These exist as member functions on `Path`

##### `relativeTo`, `relativeToOrNull`, `relativeToOrSelf`, `toRelativeString`, `toRelativeStringOrNull`

This functionality exists as the `Path.relativize` member function, which is equivalent to `relativeTo`, but with the receiver and parameter flipped. `foo.relativeTo(bar)` is equivalent to `bar.relativize(foo)`. We could potentially add a `relativizeOrNull` extension to make that pattern simpler.

##### `isRooted`

`Path` has a `root` method, so `isRooted` is equivalent to `root != null`

### New extensions

All of the simple boolean attribute checks from `java.nio.Files` were added as extensions on `Path`. These extensions are used commonly enough that it seems worth supporting them. This functionality for `File` is implemented as member methods.

The following `Path` extensions were added:

- `exists`
- `isDirectory`
- `isExecutable`
- `isFile`
- `isHidden`
- `isReadable`
- `isSameFile`
- `isSymbolicLink`
- `isWritable`

Some of these extensions take options that are forwarded to their `Files` method, so all of the extensions were implemented as functions rather than properties for consistency.

Additionally, `Path.listFiles` was added to match the `File.listFiles` method. One motivation for its addition was that it's used several times in the implementation of other file extensions. The way to list directory contents with `java.nio` is via `Files.newDirectoryStream()`, which returns an iterable object that must be closed to avoid leaking resources. It's difficult to use correctly with functions like `map` and `filter`, so this extension was added as a simpler, less error-prone alternative.

### Other changes

I added overloads of several of the read-write that take `OpenOptions` to expose the greater control that `java.nio` introduces. For example, you can use `printWriter(APPEND)` to create a `PrintWriter` that doesn't delete the contents of an existing file.

All the new extensions throw exceptions (such as `NoSuchFileException`) from `java.nio` rather than the copies from `kotlin.io`. The `kotlin.io` copies take `File` objects as parameters, and so aren't compatible with `Path`s.

### Address review comments

- Move varargs parameters to the last position
- Remove PathTreeWalk

#KT-19192
2020-10-28 07:35:54 +03:00
Ilya Gorbunov 41131e46d7 Shadow addSuppressed member with an extension
#KT-38777
2020-06-17 19:45:15 +03:00
Ilya Gorbunov 7b7263c5bf Implement common Throwable.addSuppressed/suppressed extensions
Instead of `suppressed` Array we provide `suppressedExceptions` List

#KT-23737
2020-04-13 09:32:41 +03:00
Toshiaki Kameyama 941de655c4 Add contract for 'use'
#KT-35216 Fixed
2019-12-28 02:54:29 +03:00
Ilya Gorbunov 042a8ff6a2 Provide ThreadLocalRandom wrapper only on JDK8 as it is buggy in JDK7 2018-08-30 14:50:44 +03:00
Ilya Gorbunov fa33b1b5a9 Random docs and API refinement
KT-17261
2018-08-30 14:50:40 +03:00
Ilya Gorbunov cc031e3a40 Provide common Random API
#KT-17261
2018-08-30 14:50:36 +03:00
Alexander Udalov 2a8be2cdb4 Move internal declarations in kotlin-stdlib-jdk7/8 to other packages
- in kotlin-stdlib-jdk7, package kotlin.internal -> kotlin.internal.jdk7
- in kotlin-stdlib-jdk8, package kotlin.internal -> kotlin.internal.jdk8
2017-10-11 19:23:32 +03:00
Alexander Udalov e253acd5fd Introduce kotlin-stdlib-jdk7/8 libraries, deprecate kotlin-stdlib-jre7/8
The idea is to keep all declarations in the same packages from Kotlin's
point of view, but use JvmPackageName annotation to move them to another
JVM package, to avoid the split package problem which is otherwise
unsolvable when using module path on Java 9 (KT-19258).

In this commit, kotlin-stdlib-jre7/8 are moved to kotlin-stdlib-jdk7/8
and in the subsequent commit, -jre7/8 are restored. This is done in
order to make Git recognize this as a file move to preserve history.

Include new stdlib-jdkN artifacts in manifest version tests.
2017-10-11 19:20:24 +03:00