* @brief Lists a directory under the read roots; supports bounded recursion. */
| 366 | * @brief Lists a directory under the read roots; supports bounded recursion. |
| 367 | */ |
| 368 | QJsonObject AI::FileSandbox::list(const QJsonObject& args) const |
| 369 | { |
| 370 | const auto input = args.value(QStringLiteral("path")).toString(); |
| 371 | const auto resolved = resolveRead(input.isEmpty() ? QStringLiteral(".") : input); |
| 372 | if (!resolved.ok) |
| 373 | return failure(resolved.error, resolved.hint); |
| 374 | |
| 375 | const QFileInfo info(resolved.path); |
| 376 | if (!info.isDir()) |
| 377 | return failure(QStringLiteral("not_a_directory"), |
| 378 | QStringLiteral("Use fs.read for files; fs.list expects a directory.")); |
| 379 | |
| 380 | bool truncated = false; |
| 381 | const bool recursive = args.value(QStringLiteral("recursive")).toBool(false); |
| 382 | QJsonArray rows; |
| 383 | collectEntries(resolved.path, workspaceRoot(), recursive, 0, rows, truncated); |
| 384 | |
| 385 | QJsonObject out; |
| 386 | out[QStringLiteral("ok")] = true; |
| 387 | out[QStringLiteral("path")] = displayPath(resolved.path, workspaceRoot()); |
| 388 | out[QStringLiteral("count")] = rows.size(); |
| 389 | out[QStringLiteral("entries")] = rows; |
| 390 | out[QStringLiteral("truncated")] = truncated; |
| 391 | if (truncated) |
| 392 | out[QStringLiteral("hint")] = |
| 393 | QStringLiteral("Listing capped; narrow the path or list subdirectories individually."); |
| 394 | |
| 395 | return out; |
| 396 | } |
| 397 | |
| 398 | //-------------------------------------------------------------------------------------------------- |
| 399 | // read |
nothing calls this directly
no test coverage detected