Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ fun createWriteResultObject(uri: Uri, mode: IONFILESaveMode): JSObject? =
* @return a result [JSObject] for the list of a directories contents
*/
fun createReadDirResultObject(list: List<IONFILEMetadataResult>): JSObject = JSObject().also {
it.put(OUTPUT_FILES, JSArray(list.map { child -> child.toResultObject() }))
val sorted = list.sortedWith(
compareBy<IONFILEMetadataResult>(
{ it.lastModifiedTimestamp },
{ it.createdTimestamp },
{ it.name.lowercase() },
),
)
it.put(OUTPUT_FILES, JSArray(sorted.map { child -> child.toResultObject() }))
}

/**
Expand All @@ -62,4 +69,4 @@ fun IONFILEUri.Resolved.toResultObject(): JSObject = createUriResultObject(this.
* @return a result [JSObject] for an Android [Uri]
*/
fun createUriResultObject(uri: Uri): JSObject =
JSObject().also { it.put(OUTPUT_URI, uri.toString()) }
JSObject().also { it.put(OUTPUT_URI, uri.toString()) }
14 changes: 13 additions & 1 deletion ios/Sources/FilesystemPlugin/FilesystemOperationExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ class FilesystemOperationExecutor {
try service.removeDirectory(atURL: url, includeIntermediateDirectories: recursive)
case .readdir(let url):
let directoryAttributes = try service.listDirectory(atURL: url)
.map { try fetchItemAttributesJSObject(using: service, atURL: $0) }
.map { childUrl in
(url: childUrl, attributes: try service.getItemAttributes(atURL: childUrl))
}
.sorted { lhs, rhs in
if lhs.attributes.modificationDateTimestamp != rhs.attributes.modificationDateTimestamp {
return lhs.attributes.modificationDateTimestamp < rhs.attributes.modificationDateTimestamp
}
if lhs.attributes.creationDateTimestamp != rhs.attributes.creationDateTimestamp {
return lhs.attributes.creationDateTimestamp < rhs.attributes.creationDateTimestamp
}
return lhs.url.lastPathComponent.localizedCaseInsensitiveCompare(rhs.url.lastPathComponent) == .orderedAscending
}
.map { $0.attributes.toJSResult(with: $0.url) }
resultData = [Constants.ResultDataKey.files: directoryAttributes]
case .stat(let url):
resultData = try fetchItemAttributesJSObject(using: service, atURL: url)
Expand Down