Repository navigation
Expand file tree
/
Copy pathVirtualFileSystemExample.cpp
More file actions
600 lines (511 loc) · 23.2 KB
/
Copy pathVirtualFileSystemExample.cpp
File metadata and controls
600 lines (511 loc) · 23.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
#include <chrono>
#include <cstring>
#include <thread>
#include <vector>
#include "Concurrency/WorkContractGroup.h"
#include "Concurrency/WorkService.h"
#include "EntropyCore.h"
#include "VirtualFileSystem/DirectoryHandle.h"
#include "VirtualFileSystem/FileStream.h"
#include "VirtualFileSystem/VirtualFileSystem.h"
#include "VirtualFileSystem/WriteBatch.h"
using namespace EntropyEngine::Core;
using namespace EntropyEngine::Core::Concurrency;
using namespace EntropyEngine::Core::IO;
int main() {
// Start the work service
WorkService::Config cfg{};
WorkService service(cfg);
service.start();
// Create a contract group and register it to the service
WorkContractGroup group(2000, "VFSGroup");
service.addWorkContractGroup(&group);
// Create VFS instance with custom config
VirtualFileSystem::Config vfsConfig;
vfsConfig.maxWriteLocksCached = 100; // Smaller cache for testing
vfsConfig.writeLockTimeout = std::chrono::minutes(1);
VirtualFileSystem vfs(&group, vfsConfig);
// Create a file handle for create/delete demo
auto tmp = vfs.createFileHandle("vfs_create_delete_tmp.txt");
auto c = tmp.createEmpty();
c.wait();
if (c.status() != FileOpStatus::Complete) {
ENTROPY_LOG_ERROR("createEmpty failed");
return 1;
}
auto wtmp = tmp.writeAll("Just to delete me.\n");
wtmp.wait();
auto d = tmp.remove();
d.wait();
if (d.status() != FileOpStatus::Complete) {
ENTROPY_LOG_ERROR("remove failed");
return 1;
}
// Create a file handle for main demo
auto handle = vfs.createFileHandle("vfs_example_tmp.txt");
// Write text
auto w = handle.writeAll("Hello from VFS!\nLine two.");
w.wait();
if (w.status() != FileOpStatus::Complete) {
ENTROPY_LOG_ERROR("writeAll failed");
return 1;
}
// Read all
auto rAll = handle.readAll();
rAll.wait();
if (rAll.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("readAll (text):\n" + rAll.contentsText());
} else {
ENTROPY_LOG_ERROR("readAll failed: " + rAll.errorInfo().message);
}
// Read range
auto rRange = handle.readRange(0, 5);
rRange.wait();
if (rRange.status() == FileOpStatus::Complete || rRange.status() == FileOpStatus::Partial) {
auto bytes = rRange.contentsBytes();
std::string s(reinterpret_cast<const char*>(bytes.data()), bytes.size());
ENTROPY_LOG_INFO("readRange(0,5): '" + s + "'");
}
// Write range (append-like by offset)
const char* tail = "\nAppended via writeRange.";
auto wr = handle.writeRange(rAll.contentsBytes().size(),
std::span<const std::byte>(reinterpret_cast<const std::byte*>(tail), strlen(tail)));
wr.wait();
if (wr.status() != FileOpStatus::Complete) {
ENTROPY_LOG_ERROR("writeRange failed");
}
// Read line 1 (0-based)
auto rLine = handle.readLine(1);
rLine.wait();
if (rLine.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("readLine(1): '" + rLine.contentsText() + "'");
}
// Test writeLine with atomic rename (improved performance)
auto wLine = handle.writeLine(1, "Modified line two via atomic rename");
wLine.wait();
if (wLine.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("writeLine succeeded with atomic rename");
} else {
ENTROPY_LOG_ERROR("writeLine failed: " + wLine.errorInfo().message);
}
// Test streaming API for large files
ENTROPY_LOG_INFO("Testing streaming API:");
auto stream = handle.openReadWriteStream();
if (stream && stream->good()) {
// Write some data using stream
const char* streamData = "\nData written via streaming API";
stream->seek(0, std::ios::end);
auto writeResult = stream->write(
std::span<const std::byte>(reinterpret_cast<const std::byte*>(streamData), strlen(streamData)));
stream->flush();
ENTROPY_LOG_INFO("Wrote " + std::to_string(writeResult.bytesTransferred) + " bytes via stream");
// Read back using stream
stream->seek(0, std::ios::beg);
std::vector<std::byte> buffer(256);
auto readResult = stream->read(buffer);
ENTROPY_LOG_INFO("Read " + std::to_string(readResult.bytesTransferred) + " bytes via stream");
}
// Test multiple concurrent operations to verify thread safety
ENTROPY_LOG_INFO("Testing concurrent operations:");
std::vector<FileOperationHandle> concurrentOps;
for (int i = 0; i < 5; ++i) {
auto h = vfs.createFileHandle("concurrent_test_" + std::to_string(i) + ".txt");
concurrentOps.push_back(h.writeAll("Concurrent write " + std::to_string(i)));
}
// Wait for all concurrent writes
for (auto& op : concurrentOps) {
op.wait();
if (op.status() != FileOpStatus::Complete) {
ENTROPY_LOG_ERROR("Concurrent write failed: " + op.errorInfo().message);
}
}
ENTROPY_LOG_INFO("All concurrent operations completed");
// Demonstrate concurrency: many file operations writing to the SAME file
ENTROPY_LOG_INFO("1000 file operations writing to the same file (serialized by VFS lock):");
const std::string sameFile = "vfs_contracts_same_file.txt";
// Ensure a clean file
vfs.createFileHandle(sameFile).createEmpty().wait();
// Create 1000 file operations (not nested work contracts)
std::vector<FileOperationHandle> writeOps;
writeOps.reserve(1000);
for (int i = 0; i < 1000; ++i) {
auto fh = vfs.createFileHandle(sameFile);
// Each operation writes its own line index. Lines are:
// "Work contract N wrote!"
writeOps.push_back(fh.writeLine(static_cast<size_t>(i), "Work contract " + std::to_string(i + 1) + " wrote!"));
ENTROPY_LOG_INFO("Scheduled write " + std::to_string(i + 1));
}
// Wait for all write operations to finish
for (auto& op : writeOps) {
op.wait();
if (op.status() != FileOpStatus::Complete) {
ENTROPY_LOG_ERROR("Write operation failed: " + op.errorInfo().message);
}
}
ENTROPY_LOG_INFO("All 1000 writes completed");
// Read back the file to show the results
auto verify = vfs.createFileHandle(sameFile).readAll();
verify.wait();
if (verify.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Contents of '" + sameFile + "':\n" + verify.contentsText());
} else {
ENTROPY_LOG_ERROR("Failed to read back '" + sameFile + "': " + verify.errorInfo().message);
}
// Example 4: Batch write operations
ENTROPY_LOG_INFO("=== Example 4: Batch Write Operations ===");
auto batchHandle = vfs.createFileHandle("batch_write_test.txt");
auto batch = vfs.createWriteBatch(batchHandle.metadata().path);
// Add lines in non-sequential order (demonstrating atomic reordering)
batch->writeLine(5, "This is line 5");
batch->writeLine(0, "This is line 0");
batch->writeLine(3, "This is line 3");
batch->insertLine(1, "Inserted at line 1");
batch->appendLine("This line is appended");
batch->writeLine(2, "This is line 2");
ENTROPY_LOG_INFO("Batch has " + std::to_string(batch->pendingOperations()) + " operations pending");
// Commit all operations atomically
auto batchOp = batch->commit();
batchOp.wait();
if (batchOp.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Batch write completed successfully, wrote " + std::to_string(batchOp.bytesWritten()) +
" bytes");
// Read back the result
auto batchRead = batchHandle.readAll();
batchRead.wait();
if (batchRead.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Contents after batch write:\n" + batchRead.contentsText());
}
} else {
ENTROPY_LOG_ERROR("Batch write failed: " + batchOp.errorInfo().message);
}
// Example 5: Efficient bulk update with batch
ENTROPY_LOG_INFO("=== Example 5: Efficient Bulk Update with Batch ===");
// Benchmark: Individual writeLine operations
auto individualHandle = vfs.createFileHandle("individual_write_test.txt");
individualHandle.createEmpty().wait();
auto startIndividual = std::chrono::high_resolution_clock::now();
std::vector<FileOperationHandle> individualOps;
individualOps.reserve(100);
for (int i = 0; i < 100; ++i) {
individualOps.push_back(individualHandle.writeLine(i, "Individual line " + std::to_string(i)));
}
for (auto& op : individualOps) {
op.wait();
}
auto endIndividual = std::chrono::high_resolution_clock::now();
auto individualDuration =
std::chrono::duration_cast<std::chrono::milliseconds>(endIndividual - startIndividual).count();
// Benchmark: Batch operation
auto bulkHandle = vfs.createFileHandle("bulk_update_test.txt");
auto bulkBatch = vfs.createWriteBatch(bulkHandle.metadata().path);
auto startBatch = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 100; ++i) {
bulkBatch->writeLine(i, "Batch line " + std::to_string(i));
}
auto bulkOp = bulkBatch->commit();
bulkOp.wait();
auto endBatch = std::chrono::high_resolution_clock::now();
auto batchDuration = std::chrono::duration_cast<std::chrono::milliseconds>(endBatch - startBatch).count();
// Report comparison
ENTROPY_LOG_INFO("Individual writes (100 lines): " + std::to_string(individualDuration) + "ms");
ENTROPY_LOG_INFO("Batch write (100 lines): " + std::to_string(batchDuration) + "ms");
if (individualDuration > 0) {
float speedup =
static_cast<float>(individualDuration) / static_cast<float>(batchDuration > 0 ? batchDuration : 1);
ENTROPY_LOG_INFO("Batch is " + std::to_string(speedup) + "x faster than individual operations");
}
individualHandle.remove().wait();
// Clean up test files
for (int i = 0; i < 5; ++i) {
auto h = vfs.createFileHandle("concurrent_test_" + std::to_string(i) + ".txt");
h.remove().wait();
}
// Example 6: Batch Metadata Queries
ENTROPY_LOG_INFO("=== Example 6: Batch Metadata Queries ===");
// Create some test files and keep handles
std::vector<std::string> testFilePaths;
std::vector<FileHandle> metadataHandles;
for (int i = 0; i < 10; ++i) {
auto h = vfs.createFileHandle("metadata_test_" + std::to_string(i) + ".txt");
h.writeAll("Test content " + std::to_string(i)).wait();
testFilePaths.push_back(h.metadata().path);
metadataHandles.push_back(std::move(h));
}
// Query metadata via DirectoryHandle listing with glob (no raw backend)
auto currentDir = vfs.createDirectoryHandle(".");
ListDirectoryOptions bList;
bList.globPattern = std::string("metadata_test_*.txt");
bList.sortBy = ListDirectoryOptions::ByName;
auto metaList = currentDir.list(bList);
metaList.wait();
if (metaList.status() == FileOpStatus::Complete) {
const auto& entries = metaList.directoryEntries();
ENTROPY_LOG_INFO("Retrieved metadata for " + std::to_string(entries.size()) + " files via directory listing");
for (const auto& e : entries) {
ENTROPY_LOG_INFO(" " + e.fullPath + ": exists=" + std::to_string(e.metadata.exists ? 1 : 0) +
", size=" + std::to_string(e.metadata.size) + " bytes");
}
}
// Example 7: Copy Operations with Progress
ENTROPY_LOG_INFO("=== Example 7: Copy Operations with Progress ===");
// Create a larger source file
auto sourceHandle = vfs.createFileHandle("large_source.txt");
auto destHandle = vfs.createFileHandle("large_copy.txt");
std::string largeContent;
for (int i = 0; i < 10000; ++i) {
largeContent += "This is line " + std::to_string(i) + " of the large file.\n";
}
sourceHandle.writeAll(largeContent).wait();
// Copy with progress callback
CopyOptions copyOpts;
copyOpts.overwriteExisting = true;
copyOpts.preserveAttributes = true;
copyOpts.progressCallback = [](size_t copied, size_t total) {
int percent = static_cast<int>((copied * 100) / total);
if (percent % 10 == 0 && copied > 0) {
ENTROPY_LOG_INFO(" Copy progress: " + std::to_string(percent) + "% (" + std::to_string(copied) + "/" +
std::to_string(total) + " bytes)");
}
return true;
};
// Copy using FileHandle read/write (no raw backend)
auto srcRead = sourceHandle.readAll();
srcRead.wait();
if (srcRead.status() == FileOpStatus::Complete) {
WriteOptions cwo;
cwo.truncate = true;
cwo.createIfMissing = true;
auto copyWrite = destHandle.writeAll(srcRead.contentsBytes(), cwo);
copyWrite.wait();
if (copyWrite.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Copy completed: " + std::to_string(copyWrite.bytesWritten()) + " bytes copied");
} else {
ENTROPY_LOG_ERROR("Copy failed: " + copyWrite.errorInfo().message);
}
} else {
ENTROPY_LOG_ERROR("Source read failed: " + srcRead.errorInfo().message);
}
// Example 8: Move Operations
ENTROPY_LOG_INFO("=== Example 8: Move Operations ===");
auto moveSourceHandle = vfs.createFileHandle("file_to_move.txt");
auto moveDestHandle = vfs.createFileHandle("moved_file.txt");
moveSourceHandle.writeAll("This file will be moved").wait();
// Move implemented as copy then remove via FileHandle operations
auto moveRead = moveSourceHandle.readAll();
moveRead.wait();
if (moveRead.status() == FileOpStatus::Complete) {
WriteOptions mow;
mow.truncate = true;
mow.createIfMissing = true;
auto moveWrite = moveDestHandle.writeAll(moveRead.contentsBytes(), mow);
moveWrite.wait();
if (moveWrite.status() == FileOpStatus::Complete) {
moveSourceHandle.remove().wait();
ENTROPY_LOG_INFO("Move completed successfully");
} else {
ENTROPY_LOG_ERROR("Move failed: " + moveWrite.errorInfo().message);
}
} else {
ENTROPY_LOG_ERROR("Move read failed: " + moveRead.errorInfo().message);
}
// Move with overwrite: write/truncate destination and remove source
auto moveSource2 = vfs.createFileHandle("file_to_move2.txt");
moveSource2.writeAll("Second file to move").wait();
auto moveRead2 = moveSource2.readAll();
moveRead2.wait();
if (moveRead2.status() == FileOpStatus::Complete) {
WriteOptions mow2;
mow2.truncate = true;
mow2.createIfMissing = true;
auto moveWrite2 = moveDestHandle.writeAll(moveRead2.contentsBytes(), mow2);
moveWrite2.wait();
if (moveWrite2.status() == FileOpStatus::Complete) {
moveSource2.remove().wait();
ENTROPY_LOG_INFO("Move with overwrite completed successfully");
} else {
ENTROPY_LOG_ERROR("Move with overwrite failed: " + moveWrite2.errorInfo().message);
}
}
// Example 9: Optimized Buffering
ENTROPY_LOG_INFO("=== Example 9: Optimized 64KB Buffering ===");
auto bufferedStream = handle.openBufferedStream();
if (bufferedStream && bufferedStream->good()) {
ENTROPY_LOG_INFO("Opened buffered stream with 64KB buffer for optimal performance");
}
// Example 10: File Watching
ENTROPY_LOG_INFO("=== Example 10: File System Watching ===");
// Create a directory to watch
std::filesystem::create_directory("watch_test_dir");
// Set up watch options with filtering
WatchOptions watchOpts;
watchOpts.recursive = true;
watchOpts.includePatterns = {"*.txt", "*.log"}; // Only watch text and log files
watchOpts.excludePatterns = {"*.tmp", "*.temp"}; // Ignore temp files
// Create a watch with a callback
std::atomic<int> eventCount{0};
auto watch = vfs.watchDirectory(
"watch_test_dir",
[&eventCount](const FileWatchInfo& info) {
eventCount++;
std::string eventType;
switch (info.event) {
case FileWatchEvent::Created:
eventType = "Created";
break;
case FileWatchEvent::Modified:
eventType = "Modified";
break;
case FileWatchEvent::Deleted:
eventType = "Deleted";
break;
case FileWatchEvent::Renamed:
eventType = "Renamed";
break;
}
ENTROPY_LOG_INFO("File event: " + eventType + " - " + info.path);
if (info.oldPath.has_value()) {
ENTROPY_LOG_INFO(" Old path: " + info.oldPath.value());
}
},
watchOpts);
if (watch && watch->isWatching()) {
ENTROPY_LOG_INFO("Started watching directory: watch_test_dir");
// Trigger some file events
auto testFile1 = vfs.createFileHandle("watch_test_dir/test1.txt");
testFile1.writeAll("This file should trigger a Created event").wait();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
auto testFile2 = vfs.createFileHandle("watch_test_dir/test2.log");
testFile2.writeAll("Log file created").wait();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// This file should be ignored due to exclude pattern
auto tempFile = vfs.createFileHandle("watch_test_dir/ignored.tmp");
tempFile.writeAll("This should be ignored").wait();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Modify a file
testFile1.writeAll("Modified content").wait();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Delete a file
testFile2.remove().wait();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Allow time for events to be processed
std::this_thread::sleep_for(std::chrono::milliseconds(500));
ENTROPY_LOG_INFO("File watch received " + std::to_string(eventCount.load()) + " events");
// Stop watching
watch->stop();
ENTROPY_LOG_INFO("Stopped watching directory");
// Clean up watch (decrements refcount)
vfs.unwatchDirectory(watch);
} else {
ENTROPY_LOG_ERROR("Failed to create file watch");
}
// Clean up watch test directory
vfs.createDirectoryHandle("watch_test_dir").remove(true).wait();
// Example 11: Directory Operations
ENTROPY_LOG_INFO("=== Example 11: Directory Operations ===");
// Create a directory handle
auto testDir = vfs.createDirectoryHandle("example_directory");
// Create the directory
auto createOp = testDir.create();
createOp.wait();
if (createOp.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Created directory: " + testDir.metadata().path);
} else {
ENTROPY_LOG_ERROR("Failed to create directory: " + createOp.errorInfo().message);
}
// Create some files inside the directory
auto file1 = vfs.createFileHandle("example_directory/file1.txt");
file1.writeAll("Content of file 1").wait();
auto file2 = vfs.createFileHandle("example_directory/file2.log");
file2.writeAll("Log content").wait();
auto file3 = vfs.createFileHandle("example_directory/.hidden");
file3.writeAll("Hidden file content").wait();
// Create a subdirectory
auto subDir = vfs.createDirectoryHandle("example_directory/subdir");
subDir.create().wait();
auto file4 = vfs.createFileHandle("example_directory/subdir/nested.txt");
file4.writeAll("Nested file content").wait();
// List directory contents (non-recursive, no hidden files)
ListDirectoryOptions listOpts;
listOpts.includeHidden = false;
listOpts.sortBy = ListDirectoryOptions::ByName;
auto listing = testDir.list(listOpts);
listing.wait();
if (listing.status() == FileOpStatus::Complete) {
const auto& entries = listing.directoryEntries();
ENTROPY_LOG_INFO("Directory contains " + std::to_string(entries.size()) + " visible entries (sorted by name):");
for (const auto& entry : entries) {
std::string type = entry.metadata.isDirectory ? "[DIR] " : "[FILE]";
ENTROPY_LOG_INFO(" " + type + entry.name + " (" + std::to_string(entry.metadata.size) + " bytes)");
}
}
// List with hidden files included
listOpts.includeHidden = true;
auto listingWithHidden = testDir.list(listOpts);
listingWithHidden.wait();
if (listingWithHidden.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Directory contains " + std::to_string(listingWithHidden.directoryEntries().size()) +
" total entries (including hidden)");
}
// Recursive listing
listOpts.recursive = true;
listOpts.includeHidden = false;
auto recursiveListing = testDir.list(listOpts);
recursiveListing.wait();
if (recursiveListing.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Recursive listing found " + std::to_string(recursiveListing.directoryEntries().size()) +
" entries:");
for (const auto& entry : recursiveListing.directoryEntries()) {
ENTROPY_LOG_INFO(" " + entry.fullPath);
}
}
// List with glob pattern filter
listOpts.recursive = false;
listOpts.globPattern = "*.txt";
auto filteredListing = testDir.list(listOpts);
filteredListing.wait();
if (filteredListing.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Files matching *.txt: " + std::to_string(filteredListing.directoryEntries().size()));
for (const auto& entry : filteredListing.directoryEntries()) {
ENTROPY_LOG_INFO(" " + entry.name);
}
}
// List with pagination (max 2 results)
listOpts.globPattern = std::nullopt;
listOpts.maxResults = 2;
listOpts.sortBy = ListDirectoryOptions::BySize;
auto paginatedListing = testDir.list(listOpts);
paginatedListing.wait();
if (paginatedListing.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("First 2 entries (sorted by size):");
for (const auto& entry : paginatedListing.directoryEntries()) {
ENTROPY_LOG_INFO(" " + entry.name + " - " + std::to_string(entry.metadata.size) + " bytes");
}
}
// Get directory metadata
auto dirMeta = testDir.getMetadata();
dirMeta.wait();
if (dirMeta.status() == FileOpStatus::Complete && dirMeta.metadata().has_value()) {
const auto& meta = dirMeta.metadata().value();
ENTROPY_LOG_INFO("Directory metadata:");
ENTROPY_LOG_INFO(" Exists: " + std::to_string(meta.exists));
ENTROPY_LOG_INFO(" Is directory: " + std::to_string(meta.isDirectory));
ENTROPY_LOG_INFO(" Readable: " + std::to_string(meta.readable));
ENTROPY_LOG_INFO(" Writable: " + std::to_string(meta.writable));
}
// Remove directory (recursive)
auto removeOp = testDir.remove(true);
removeOp.wait();
if (removeOp.status() == FileOpStatus::Complete) {
ENTROPY_LOG_INFO("Removed directory: " + testDir.metadata().path);
} else {
ENTROPY_LOG_ERROR("Failed to remove directory: " + removeOp.errorInfo().message);
}
// Clean up test files
ENTROPY_LOG_INFO("Cleaning up test files...");
for (auto& h : metadataHandles) {
h.remove().wait();
}
// Clean up service
service.stop();
return 0;
}