diff --git a/mirai-core/src/commonMain/kotlin/contact/file/AbsoluteFolderImpl.kt b/mirai-core/src/commonMain/kotlin/contact/file/AbsoluteFolderImpl.kt index 3ab2f3afd..81ad72ff3 100644 --- a/mirai-core/src/commonMain/kotlin/contact/file/AbsoluteFolderImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/file/AbsoluteFolderImpl.kt @@ -363,6 +363,9 @@ internal class AbsoluteFolderImpl( override suspend fun resolveFolder(name: String): AbsoluteFolder? { if (name.isBlank()) throw IllegalArgumentException("folder name cannot be blank.") if (!FileSystem.isLegal(name)) return null + if (name[0] == '/') { + return root.resolveFolder(name.substring(1)) + } return getItemsFlow().firstOrNull { it.folderInfo?.folderName == name }?.resolve() as AbsoluteFolder? } @@ -380,6 +383,10 @@ internal class AbsoluteFolderImpl( if (path.isBlank()) throw IllegalArgumentException("path cannot be blank.") if (!FileSystem.isLegal(path)) return emptyFlow() + if (path[0] == '/') { + return root.resolveFiles(path.substring(1)) + } + if (!path.contains('/')) { return getItemsFlow().filter { it.fileInfo?.fileName == path }.map { it.resolve() as AbsoluteFile } } @@ -392,8 +399,14 @@ internal class AbsoluteFolderImpl( if (path.isBlank()) throw IllegalArgumentException("path cannot be blank.") if (!FileSystem.isLegal(path)) return Stream.empty() + if (path[0] == '/') { + return root.resolveFilesStream(path.substring(1)) + } + if (!path.contains('/')) { - return getItemsSequence().filter { it.fileInfo?.fileName == path }.map { it.resolve() as AbsoluteFile } + return getItemsSequence() + .filter { it.fileInfo?.fileName == path } + .map { it.resolve() as AbsoluteFile } .asStream() } @@ -403,6 +416,9 @@ internal class AbsoluteFolderImpl( override suspend fun resolveAll(path: String): Flow { if (path.isBlank()) throw IllegalArgumentException("path cannot be blank.") if (!FileSystem.isLegal(path)) return emptyFlow() + if (path[0] == '/') { + return root.resolveAll(path.substring(1)) + } if (!path.contains('/')) { return getItemsFlow().mapNotNull { it.resolve() } } @@ -414,6 +430,9 @@ internal class AbsoluteFolderImpl( override suspend fun resolveAllStream(path: String): Stream { if (path.isBlank()) throw IllegalArgumentException("path cannot be blank.") if (!FileSystem.isLegal(path)) return Stream.empty() + if (path[0] == '/') { + return root.resolveAllStream(path.substring(1)) + } if (!path.contains('/')) { return getItemsSequence().mapNotNull { it.resolve() }.asStream() } diff --git a/mirai-core/src/commonMain/kotlin/contact/file/AbstractAbsoluteFileFolder.kt b/mirai-core/src/commonMain/kotlin/contact/file/AbstractAbsoluteFileFolder.kt index 58cca374f..1eba1ca73 100644 --- a/mirai-core/src/commonMain/kotlin/contact/file/AbstractAbsoluteFileFolder.kt +++ b/mirai-core/src/commonMain/kotlin/contact/file/AbstractAbsoluteFileFolder.kt @@ -31,6 +31,7 @@ internal fun AbsoluteFolder.impl(): AbsoluteFolderImpl = this.cast() internal val AbsoluteFolder?.idOrRoot get() = this?.id ?: AbsoluteFolder.ROOT_FOLDER_ID internal val AbstractAbsoluteFileFolder.parentOrRoot get() = parent ?: contact.files.root +internal val AbstractAbsoluteFileFolder.root get() = contact.files.root /** * @see AbsoluteFileFolder