diff --git a/libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt b/libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt index 82701ce7309..5599303ca31 100644 --- a/libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt +++ b/libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt @@ -62,16 +62,14 @@ private fun String.getRootLength(): Int { * * @return string representing the root for this file, or empty string is this file name is relative. */ -@Deprecated("This property has unclear semantics and will become internal soon.") -public val File.rootName: String +internal val File.rootName: String get() = path.substring(0, path.getRootLength()) /** * Returns root component of this abstract name, like / from /home/user, or C:\ from C:\file.tmp, * or //my.host/home for //my.host/home/user */ -@Deprecated("This property has unclear semantics and will become internal soon.") -public val File.root: File +internal val File.root: File get() = File(rootName) /** @@ -89,16 +87,9 @@ public val File.isRooted: Boolean * @property segments the list of [File] objects representing every directory in the path to the file, * up to an including the file itself. */ -@Deprecated("FilePathComponents has unclear semantics and will become internal soon.") -public data class FilePathComponents +internal data class FilePathComponents internal constructor(public val root: File, public val segments: List) { - @Deprecated("This constructor will be removed soon. Use File.toComponents() extension to create an instance of FilePathComponents.") - constructor (rootName: String, fileList: List): this(File(rootName), fileList) - - @Deprecated("Use 'segments' property instead.", ReplaceWith("segments")) - public val fileList: List get() = segments - /** * Returns a string representing the root for this file, or an empty string is this file name is relative. */ @@ -114,9 +105,6 @@ public data class FilePathComponents */ public val size: Int get() = segments.size - @Deprecated("Use 'size' property instead.", ReplaceWith("size")) - public fun size(): Int = size - /** * Returns a sub-path of the path, starting with the directory at the specified [beginIndex] and up * to the specified [endIndex]. @@ -142,9 +130,6 @@ internal fun File.toComponents(): FilePathComponents { return FilePathComponents(File(rootName), list) } -@Deprecated("FilePathComponents has unclear semantics and will become internal soon.") -public fun File.filePathComponents(): FilePathComponents = toComponents() - /** * Returns a relative pathname which is a subsequence of this pathname, * beginning from component [beginIndex], inclusive, @@ -155,5 +140,4 @@ public fun File.filePathComponents(): FilePathComponents = toComponents() * or [endIndex] is greater than existing number of components, * or [beginIndex] is greater than [endIndex]. */ -@Deprecated("This function can fail since path segment count isn't known in advance.") -public fun File.subPath(beginIndex: Int, endIndex: Int): File = toComponents().subPath(beginIndex, endIndex) +internal fun File.subPath(beginIndex: Int, endIndex: Int): File = toComponents().subPath(beginIndex, endIndex) diff --git a/libraries/stdlib/test/io/Files.kt b/libraries/stdlib/test/io/Files.kt index 82b2b776855..184dd0dcf8c 100644 --- a/libraries/stdlib/test/io/Files.kt +++ b/libraries/stdlib/test/io/Files.kt @@ -182,9 +182,10 @@ class FilesTest { assertEquals(File("../../test"), File("test").relativeTo(File("dir/dir"))) } +/* private fun checkFilePathComponents(f: File, root: File, elements: List) { assertEquals(root, f.root) - val components = f.filePathComponents() + val components = f.toComponents() assertEquals(root, components.root) assertEquals(elements, components.segments.map { it.toString() }) } @@ -209,25 +210,26 @@ class FilesTest { checkFilePathComponents(File("."), File(""), listOf(".")) checkFilePathComponents(File(".."), File(""), listOf("..")) } +*/ @test fun fileRoot() { val rooted = File("/foo/bar") assertTrue(rooted.isRooted) - assertEquals("/", rooted.root.invariantSeparatorsPath) +// assertEquals("/", rooted.root.invariantSeparatorsPath) if (isBackslashSeparator) { val diskRooted = File("""C:\foo\bar""") assertTrue(rooted.isRooted) - assertEquals("""C:\""", diskRooted.rootName) +// assertEquals("""C:\""", diskRooted.rootName) val networkRooted = File("""\\network\share\""") assertTrue(networkRooted.isRooted) - assertEquals("""\\network\share""", networkRooted.rootName) +// assertEquals("""\\network\share""", networkRooted.rootName) } val relative = File("foo/bar") assertFalse(relative.isRooted) - assertEquals("", relative.rootName) +// assertEquals("", relative.rootName) } @test fun startsWith() { @@ -273,6 +275,7 @@ class FilesTest { } } +/* @test fun subPath() { if (isBackslashSeparator) { // Check only in Windows @@ -283,6 +286,7 @@ class FilesTest { assertEquals(File("foo"), File("/foo/bar/gav/hi").subPath(0, 1)) assertEquals(File("gav/hi"), File("/foo/bar/gav/hi").subPath(2, 4)) } +*/ @test fun normalize() { assertEquals(File("/foo/bar/baaz"), File("/foo/./bar/gav/../baaz").normalize())