MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / list

Method list

app/src/AI/FileSandbox.cpp:368–396  ·  view source on GitHub ↗

* @brief Lists a directory under the read roots; supports bounded recursion. */

Source from the content-addressed store, hash-verified

366 * @brief Lists a directory under the read roots; supports bounded recursion.
367 */
368QJsonObject 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

Callers

nothing calls this directly

Calls 6

failureFunction · 0.85
collectEntriesFunction · 0.85
displayPathFunction · 0.85
isEmptyMethod · 0.80
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected