Skip to content

Commit 9b2e174

Browse files
committed
Add flag for disabling file size on localfs.
VFS::ls is non-virtual and its signature varies across filesystems. This also allows us to use a single implementation instead of duplicating the logic.
1 parent 523230a commit 9b2e174

File tree

17 files changed

+30
-23
lines changed

17 files changed

+30
-23
lines changed

tiledb/sm/filesystem/azure.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ std::vector<std::string> Azure::ls(
638638
return paths;
639639
}
640640

641-
std::vector<directory_entry> Azure::ls_with_sizes(const URI& uri) const {
641+
std::vector<directory_entry> Azure::ls_with_sizes(const URI& uri, bool) const {
642642
return ls_with_sizes(uri, "/");
643643
}
644644

tiledb/sm/filesystem/azure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ class Azure : public FilesystemBase {
459459
* @return All entries that are contained in the prefix URI.
460460
*/
461461
std::vector<tiledb::common::filesystem::directory_entry> ls_with_sizes(
462-
const URI& uri) const override;
462+
const URI& uri, bool get_sizes) const override;
463463

464464
/**
465465
* Lists objects and object information that start with `uri`.

tiledb/sm/filesystem/failing_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class FailingFS : public FilesystemBase {
8888
}
8989

9090
virtual std::vector<tiledb::common::filesystem::directory_entry>
91-
ls_with_sizes(const URI&) const override {
91+
ls_with_sizes(const URI&, bool) const override {
9292
throw get_exception();
9393
}
9494

tiledb/sm/filesystem/filesystem_base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ class FilesystemBase {
147147
* Retrieves all the entries contained in the parent.
148148
*
149149
* @param parent The target directory to list.
150+
* @param get_sizes Flag to toggle retrieving file sizes.
150151
* @return All entries that are contained in the parent
151152
*/
152153
virtual std::vector<tiledb::common::filesystem::directory_entry>
153-
ls_with_sizes(const URI& parent) const = 0;
154+
ls_with_sizes(const URI& parent, bool get_sizes = true) const = 0;
154155

155156
/**
156157
* Lists objects and object information that start with `prefix`, invoking

tiledb/sm/filesystem/gcs.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ std::vector<directory_entry> GCS::ls_with_sizes(
510510
return entries;
511511
}
512512

513-
std::vector<directory_entry> GCS::ls_with_sizes(const URI& uri) const {
513+
std::vector<directory_entry> GCS::ls_with_sizes(const URI& uri, bool) const {
514514
return ls_with_sizes(uri, "/", -1);
515515
}
516516

tiledb/sm/filesystem/gcs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class GCS : public FilesystemBase {
358358
* @return A list of directory_entry objects.
359359
*/
360360
std::vector<tiledb::common::filesystem::directory_entry> ls_with_sizes(
361-
const URI& uri) const override;
361+
const URI& uri, bool get_sizes) const override;
362362

363363
/**
364364
* Copies the directory at 'old_uri' to `new_uri`.

tiledb/sm/filesystem/mem_filesystem.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,15 @@ Status MemFilesystem::ls(
381381
const std::string& path, std::vector<std::string>* const paths) const {
382382
iassert(paths);
383383

384-
for (auto& fs : ls_with_sizes(URI(path))) {
384+
for (auto& fs : ls_with_sizes(URI(path), true)) {
385385
paths->emplace_back(fs.path().native());
386386
}
387387

388388
return Status::Ok();
389389
}
390390

391391
std::vector<directory_entry> MemFilesystem::ls_with_sizes(
392-
const URI& path) const {
392+
const URI& path, bool) const {
393393
auto abspath = path.to_path();
394394
std::vector<std::string> tokens = tokenize(abspath);
395395

tiledb/sm/filesystem/mem_filesystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class MemFilesystem : public FilesystemBase {
159159
* @return A list of directory_entry objects
160160
*/
161161
std::vector<tiledb::common::filesystem::directory_entry> ls_with_sizes(
162-
const URI& path) const override;
162+
const URI& path, bool get_sizes) const override;
163163

164164
/**
165165
* Move a given filesystem path.

tiledb/sm/filesystem/posix.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ void Posix::write(
361361
}
362362
}
363363

364-
std::vector<directory_entry> Posix::ls_with_sizes(const URI& uri) const {
364+
std::vector<directory_entry> Posix::ls_with_sizes(
365+
const URI& uri, bool get_sizes) const {
365366
std::string path = uri.to_path();
366367
struct dirent* next_path = nullptr;
367368
auto dir = PosixDIR::open(path);
@@ -379,7 +380,8 @@ std::vector<directory_entry> Posix::ls_with_sizes(const URI& uri) const {
379380
if (next_path->d_type == DT_DIR) {
380381
entries.emplace_back(abspath, 0, true);
381382
} else {
382-
entries.emplace_back(abspath, file_size(URI(abspath)), false);
383+
entries.emplace_back(
384+
abspath, get_sizes ? file_size(URI(abspath)) : 0, false);
383385
}
384386
}
385387
return entries;

tiledb/sm/filesystem/posix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class Posix : public LocalFilesystem {
228228
* @return A list of directory_entry objects
229229
*/
230230
std::vector<tiledb::common::filesystem::directory_entry> ls_with_sizes(
231-
const URI& uri) const override;
231+
const URI& uri, bool get_sizes) const override;
232232

233233
/**
234234
* Lists files one level deep under a given path.

0 commit comments

Comments
 (0)