override fun loadObjects()

in jetbrains-core/src/software/aws/toolkits/jetbrains/services/s3/editor/S3TreeNode.kt [101:152]


    override fun loadObjects(continuationMarker: String?): List<S3TreeNode> {
        try {
            val response = runBlocking {
                bucket.listObjects(key, continuationMarker)
            }

            val continuation = listOfNotNull(
                response.nextContinuationToken()?.let {
                    S3TreeContinuationNode(bucket, this, this.key, it)
                }
            )

            val folders = response.commonPrefixes()?.map { S3TreeDirectoryNode(bucket, this, it.prefix()) } ?: emptyList()

            val s3Objects = response
                .contents()
                ?.filterNotNull()
                // filter out the directory root
                // if the root was a non-delimited prefix, it should not be filtered out
                ?.filterNot { it.key() == key && (this as? S3TreePrefixedDirectoryNode)?.isDelimited() != true }
                ?.map { S3TreeObjectNode(this, it.key(), it.size(), it.lastModified()) }
                ?: emptyList()

            val results = (folders + s3Objects).sortedBy { it.key } + continuation
            if (results.isEmpty()) {
                return listOf(S3TreeEmptyNode(bucket, this))
            }

            return results
        } catch (e: NoSuchBucketException) {
            bucket.handleDeletedBucket()
            return emptyList()
        } catch (e: S3Exception) {
            e.notifyError("Access denied to bucket")
            return buildList {
                if (continuationMarker != null) {
                    add(S3TreeErrorContinuationNode(bucket, this@S3TreeDirectoryNode, this@S3TreeDirectoryNode.key, continuationMarker))
                } else {
                    add(S3TreeErrorNode(bucket, this@S3TreeDirectoryNode))
                }
            }
        } catch (e: Exception) {
            LOG.error(e) { "Loading objects failed!" }
            return buildList {
                if (continuationMarker != null) {
                    add(S3TreeErrorContinuationNode(bucket, this@S3TreeDirectoryNode, this@S3TreeDirectoryNode.key, continuationMarker))
                } else {
                    add(S3TreeErrorNode(bucket, this@S3TreeDirectoryNode))
                }
            }
        }
    }