version / print-version (push) Successful in 2s
Users need to see at a glance what fills a disk and to remove the largest entries without digging through a file manager. The treemap makes sizes comparable, the scan runs off the UI thread, and removing an entry updates the tree in place instead of rescanning.
46 lines
989 B
C++
46 lines
989 B
C++
#pragma once
|
|
|
|
#include "core/disk-node.h"
|
|
#include "core/disk-scanner.h"
|
|
|
|
#include <QDir>
|
|
#include <QFile>
|
|
#include <memory>
|
|
|
|
// Test helpers only: they keep the fixtures readable without hiding behaviour.
|
|
namespace test_helpers {
|
|
|
|
inline bool writeFile(const QString &path, int bytes)
|
|
{
|
|
QFile file(path);
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
|
return false;
|
|
}
|
|
return file.write(QByteArray(bytes, 'x')) == bytes;
|
|
}
|
|
|
|
inline DiskNode *childNamed(const DiskNode &node, const QString &name)
|
|
{
|
|
for (const auto &child : node.children) {
|
|
if (child->name == name) {
|
|
return child.get();
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
inline std::shared_ptr<DiskNode> scan(const QString &path, ScanStats *stats = nullptr)
|
|
{
|
|
DiskScanner scanner(path);
|
|
scanner.start();
|
|
if (!scanner.wait(30000)) {
|
|
return nullptr;
|
|
}
|
|
if (stats) {
|
|
*stats = scanner.stats();
|
|
}
|
|
return scanner.takeTree();
|
|
}
|
|
|
|
} // namespace test_helpers
|