Remove options to include root in Ls

This commit is contained in:
Ming Ming 2022-01-02 00:29:10 +08:00
parent 62396a91a4
commit c26fa28594
2 changed files with 8 additions and 40 deletions

View file

@ -7,20 +7,14 @@ class Ls {
/// List all files under a dir
///
/// The resulting list would normally also include the [root] dir. If
/// [shouldExcludeRootDir] == true, such entry will be removed
Future<List<File>> call(Account account, File root,
{bool shouldExcludeRootDir = true}) async {
final products = await fileRepo.list(account, root);
if (shouldExcludeRootDir) {
// filter out root file
final trimmedRootPath = root.path.trimAny("/");
return products
.where((element) => element.path.trimAny("/") != trimmedRootPath)
.toList();
} else {
return products;
}
/// The dir itself is not included in the returned list
Future<List<File>> call(Account account, File dir) async {
final products = await fileRepo.list(account, dir);
// filter out root file
final trimmedRootPath = dir.path.trimAny("/");
return products
.where((element) => element.path.trimAny("/") != trimmedRootPath)
.toList();
}
final FileRepo fileRepo;

View file

@ -29,32 +29,6 @@ void main() {
),
]);
});
test("shouldExcludeRootDir == false", () async {
expect(
await Ls(_MockFileRepo())(
util.buildAccount(),
File(
path: "remote.php/dav/files/admin",
),
shouldExcludeRootDir: false),
[
File(
path: "remote.php/dav/files/admin",
isCollection: true,
),
File(
path: "remote.php/dav/files/admin/test1.jpg",
),
File(
path: "remote.php/dav/files/admin/test2.jpg",
),
File(
path: "remote.php/dav/files/admin/d1",
isCollection: true,
),
]);
});
});
}