Compare commits
12 Commits
v0.2.1
..
afb089bee6
| Author | SHA1 | Date | |
|---|---|---|---|
| afb089bee6 | |||
| 79001370b8 | |||
| 07fc419f1e | |||
| 70d728f9c3 | |||
| e0d7cbb29a | |||
| 918e081834 | |||
| d2863997e8 | |||
| 7e6875ee1c | |||
| 168c5ad3ac | |||
| 5726ff3f62 | |||
| 0b93c8c124 | |||
| 4cb6fdf540 |
@@ -1,9 +1,12 @@
|
|||||||
name: release
|
name: ci-release
|
||||||
|
|
||||||
"on":
|
"on":
|
||||||
push:
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
tags:
|
tags:
|
||||||
- "v[0-9]*.[0-9]*.[0-9]*"
|
- "v[0-9]*.[0-9]*.[0-9]*"
|
||||||
|
pull_request:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
@@ -16,7 +19,8 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Verify tag matches VERSION
|
- name: Verify release tag matches VERSION
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
tag="${GITHUB_REF##*/}"
|
tag="${GITHUB_REF##*/}"
|
||||||
@@ -30,6 +34,10 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: cmake --build build --parallel
|
run: cmake --build build --parallel
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
shell: bash
|
||||||
|
run: ctest --test-dir build --output-on-failure
|
||||||
|
|
||||||
- name: Smoke test GUI
|
- name: Smoke test GUI
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -38,6 +46,10 @@ jobs:
|
|||||||
status="$?"
|
status="$?"
|
||||||
test "$status" = 0 || test "$status" = 124
|
test "$status" = 0 || test "$status" = 124
|
||||||
|
|
||||||
|
- name: Verify Linux binary
|
||||||
|
shell: bash
|
||||||
|
run: test -x build/searchmyfiles
|
||||||
|
|
||||||
- name: Lint YAML
|
- name: Lint YAML
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -45,9 +57,10 @@ jobs:
|
|||||||
-v "$PWD:/work" \
|
-v "$PWD:/work" \
|
||||||
-w /work \
|
-w /work \
|
||||||
cytopia/yamllint:latest \
|
cytopia/yamllint:latest \
|
||||||
-c .yamllint .
|
-c .yamllint .gitea
|
||||||
|
|
||||||
linux-amd64:
|
publish-linux-amd64:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
needs: verify
|
needs: verify
|
||||||
runs-on: [self-hosted, linux, arch, homelab]
|
runs-on: [self-hosted, linux, arch, homelab]
|
||||||
env:
|
env:
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
name: ci
|
|
||||||
|
|
||||||
"on":
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-linux-amd64:
|
|
||||||
runs-on: [self-hosted, linux, arch, homelab]
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Configure release build
|
|
||||||
shell: bash
|
|
||||||
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
shell: bash
|
|
||||||
run: cmake --build build --parallel
|
|
||||||
|
|
||||||
- name: Smoke test GUI
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set +e
|
|
||||||
QT_QPA_PLATFORM=offscreen timeout 3s ./build/searchmyfiles
|
|
||||||
status="$?"
|
|
||||||
test "$status" = 0 || test "$status" = 124
|
|
||||||
|
|
||||||
- name: Verify Linux binary
|
|
||||||
shell: bash
|
|
||||||
run: test -x build/searchmyfiles
|
|
||||||
|
|
||||||
lint-yaml:
|
|
||||||
runs-on: [self-hosted, linux, arch, homelab]
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Lint workflow files
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
docker run --rm \
|
|
||||||
-v "$PWD:/work" \
|
|
||||||
-w /work \
|
|
||||||
cytopia/yamllint:latest \
|
|
||||||
-c .yamllint .
|
|
||||||
@@ -1 +1,7 @@
|
|||||||
/build/
|
/build/
|
||||||
|
/cmake-build-*/
|
||||||
|
/out/
|
||||||
|
/.idea/
|
||||||
|
/.vscode/
|
||||||
|
/CMakeLists.txt.user
|
||||||
|
/CMakeLists.txt.user.*
|
||||||
|
|||||||
@@ -5,6 +5,44 @@ All notable changes to FolderScope are documented here.
|
|||||||
The project uses [Semantic Versioning](https://semver.org/). Release tags are
|
The project uses [Semantic Versioning](https://semver.org/). Release tags are
|
||||||
formatted as `vMAJOR.MINOR.PATCH`.
|
formatted as `vMAJOR.MINOR.PATCH`.
|
||||||
|
|
||||||
|
## [0.2.4] - 2026-07-25
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Corrected result-table context menu positioning.
|
||||||
|
- Added validation for ISO date filters instead of silently accepting invalid
|
||||||
|
input.
|
||||||
|
- Replaced the 2 GB size-filter limit with precise 64-bit inputs.
|
||||||
|
- Preserved visible table order when acting on multiple selected files.
|
||||||
|
- Made release preparation reject untracked files.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added automated tests for search primitives, large size inputs, and release
|
||||||
|
safeguards.
|
||||||
|
- Added the test suite to the CI verification gate.
|
||||||
|
|
||||||
|
## [0.2.3] - 2026-07-25
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added a persistent cache for duplicate hashes and file-content matches with
|
||||||
|
automatic invalidation when files change.
|
||||||
|
- Added cache controls and a context menu on column headers for per-column and
|
||||||
|
global automatic width.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Renamed duplicate result columns to `Duplicate Set` and `Keeper Priority`,
|
||||||
|
with tooltips explaining which copy is preferred.
|
||||||
|
|
||||||
|
## [0.2.2] - 2026-07-25
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Scoped workflow YAML linting to the `.gitea` source directory.
|
||||||
|
- Combined CI and tag-gated release publishing into one workflow.
|
||||||
|
|
||||||
## [0.2.1] - 2026-07-25
|
## [0.2.1] - 2026-07-25
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
@@ -25,3 +63,6 @@ formatted as `vMAJOR.MINOR.PATCH`.
|
|||||||
|
|
||||||
[0.2.0]: https://gitea.forust.xyz/forust/folderscope/releases/tag/v0.2.0
|
[0.2.0]: https://gitea.forust.xyz/forust/folderscope/releases/tag/v0.2.0
|
||||||
[0.2.1]: https://gitea.forust.xyz/forust/folderscope/releases/tag/v0.2.1
|
[0.2.1]: https://gitea.forust.xyz/forust/folderscope/releases/tag/v0.2.1
|
||||||
|
[0.2.2]: https://gitea.forust.xyz/forust/folderscope/releases/tag/v0.2.2
|
||||||
|
[0.2.3]: https://gitea.forust.xyz/forust/folderscope/releases/tag/v0.2.3
|
||||||
|
[0.2.4]: https://gitea.forust.xyz/forust/folderscope/releases/tag/v0.2.4
|
||||||
|
|||||||
+38
-1
@@ -14,14 +14,51 @@ set(CMAKE_AUTOMOC ON)
|
|||||||
|
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Widgets Concurrent DBus)
|
find_package(Qt6 REQUIRED COMPONENTS Widgets Concurrent DBus)
|
||||||
|
|
||||||
|
add_library(folderscope_core STATIC
|
||||||
|
src/search_core.cpp
|
||||||
|
src/search_core.h
|
||||||
|
)
|
||||||
|
target_link_libraries(folderscope_core PUBLIC Qt6::Core)
|
||||||
|
target_compile_options(folderscope_core PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
|
target_include_directories(folderscope_core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||||
|
|
||||||
qt_add_executable(searchmyfiles
|
qt_add_executable(searchmyfiles
|
||||||
|
src/long_long_spin_box.cpp
|
||||||
|
src/long_long_spin_box.h
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(searchmyfiles PRIVATE Qt6::Widgets Qt6::Concurrent Qt6::DBus)
|
target_link_libraries(searchmyfiles PRIVATE folderscope_core Qt6::Widgets Qt6::Concurrent Qt6::DBus)
|
||||||
target_compile_options(searchmyfiles PRIVATE -Wall -Wextra -Wpedantic)
|
target_compile_options(searchmyfiles PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
target_compile_definitions(searchmyfiles PRIVATE FOLDERSCOPE_VERSION="${PROJECT_VERSION}")
|
target_compile_definitions(searchmyfiles PRIVATE FOLDERSCOPE_VERSION="${PROJECT_VERSION}")
|
||||||
|
|
||||||
install(TARGETS searchmyfiles RUNTIME DESTINATION bin)
|
install(TARGETS searchmyfiles RUNTIME DESTINATION bin)
|
||||||
install(FILES packaging/searchmyfiles.desktop
|
install(FILES packaging/searchmyfiles.desktop
|
||||||
DESTINATION share/applications)
|
DESTINATION share/applications)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
if (BUILD_TESTING)
|
||||||
|
find_package(Qt6 REQUIRED COMPONENTS Test)
|
||||||
|
|
||||||
|
qt_add_executable(search_core_tests
|
||||||
|
tests/search_core_test.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(search_core_tests PRIVATE folderscope_core Qt6::Test)
|
||||||
|
target_compile_options(search_core_tests PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
|
add_test(NAME search-core COMMAND search_core_tests)
|
||||||
|
|
||||||
|
qt_add_executable(long_long_spin_box_tests
|
||||||
|
src/long_long_spin_box.cpp
|
||||||
|
src/long_long_spin_box.h
|
||||||
|
tests/long_long_spin_box_test.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(long_long_spin_box_tests PRIVATE Qt6::Widgets Qt6::Test)
|
||||||
|
target_compile_options(long_long_spin_box_tests PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
|
target_include_directories(long_long_spin_box_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||||
|
add_test(NAME long-long-spin-box COMMAND long_long_spin_box_tests)
|
||||||
|
set_tests_properties(long-long-spin-box PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
|
||||||
|
|
||||||
|
add_test(NAME release-rejects-untracked
|
||||||
|
COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/tests/release_dirty_test.sh"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/release.sh")
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ single window.
|
|||||||
- filter by name patterns, size, timestamps, and file attributes;
|
- filter by name patterns, size, timestamps, and file attributes;
|
||||||
- inspect duplicate files and files with matching names;
|
- inspect duplicate files and files with matching names;
|
||||||
- search inside file contents, including text and hex;
|
- search inside file contents, including text and hex;
|
||||||
|
- reuse a persistent, automatically invalidated cache for content matches and
|
||||||
|
duplicate hashes;
|
||||||
- show folder summaries and duplicate groups;
|
- show folder summaries and duplicate groups;
|
||||||
- sort, resize, hide, and restore columns;
|
- sort, resize, hide, and restore columns, including per-column header actions;
|
||||||
- export results to CSV, TSV/TXT, HTML, XML, and JSON;
|
- export results to CSV, TSV/TXT, HTML, XML, and JSON;
|
||||||
- open files and folders, copy paths, and use context actions from the results
|
- open files and folders, copy paths, and use context actions from the results
|
||||||
table;
|
table;
|
||||||
@@ -34,6 +36,12 @@ cmake --build build -j
|
|||||||
./build/searchmyfiles
|
./build/searchmyfiles
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Run the automated tests:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ctest --test-dir build --output-on-failure
|
||||||
|
```
|
||||||
|
|
||||||
Install into the current system:
|
Install into the current system:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ fi
|
|||||||
version="$1"
|
version="$1"
|
||||||
tag="v${version}"
|
tag="v${version}"
|
||||||
|
|
||||||
if ! git diff --quiet || ! git diff --cached --quiet; then
|
if [[ -n "$(git status --porcelain)" ]]; then
|
||||||
echo "Refusing to release with uncommitted changes." >&2
|
echo "Refusing to release with uncommitted changes." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
#include "long_long_spin_box.h"
|
||||||
|
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
LongLongSpinBox::LongLongSpinBox(QWidget *parent) : QAbstractSpinBox(parent)
|
||||||
|
{
|
||||||
|
setValue(0);
|
||||||
|
connect(this, &QAbstractSpinBox::editingFinished, this, &LongLongSpinBox::commitText);
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 LongLongSpinBox::value() const
|
||||||
|
{
|
||||||
|
qint64 parsed = value_;
|
||||||
|
return valueFromText(lineEdit()->text(), parsed) ? parsed : value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LongLongSpinBox::setValue(qint64 value)
|
||||||
|
{
|
||||||
|
value_ = std::clamp(value, minimum_, maximum_);
|
||||||
|
lineEdit()->setText(textFromValue(value_));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LongLongSpinBox::setRange(qint64 minimum, qint64 maximum)
|
||||||
|
{
|
||||||
|
minimum_ = minimum;
|
||||||
|
maximum_ = std::max(minimum, maximum);
|
||||||
|
setValue(value_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LongLongSpinBox::setSingleStep(qint64 step)
|
||||||
|
{
|
||||||
|
singleStep_ = std::max<qint64>(1, step);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LongLongSpinBox::setSuffix(const QString &suffix)
|
||||||
|
{
|
||||||
|
suffix_ = suffix;
|
||||||
|
setValue(value());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LongLongSpinBox::setSpecialValueText(const QString &text)
|
||||||
|
{
|
||||||
|
specialValueText_ = text;
|
||||||
|
setValue(value());
|
||||||
|
}
|
||||||
|
|
||||||
|
QValidator::State LongLongSpinBox::validate(QString &input, int &position) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(position);
|
||||||
|
if (!specialValueText_.isEmpty() && input == specialValueText_)
|
||||||
|
return QValidator::Acceptable;
|
||||||
|
|
||||||
|
QString number = input;
|
||||||
|
if (!suffix_.isEmpty() && number.endsWith(suffix_))
|
||||||
|
number.chop(suffix_.size());
|
||||||
|
number = number.trimmed();
|
||||||
|
if (number.isEmpty() || number == QStringLiteral("-"))
|
||||||
|
return QValidator::Intermediate;
|
||||||
|
|
||||||
|
qint64 parsed = 0;
|
||||||
|
if (!valueFromText(input, parsed))
|
||||||
|
return QValidator::Invalid;
|
||||||
|
return parsed >= minimum_ && parsed <= maximum_
|
||||||
|
? QValidator::Acceptable : QValidator::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LongLongSpinBox::fixup(QString &input) const
|
||||||
|
{
|
||||||
|
qint64 parsed = value_;
|
||||||
|
input = valueFromText(input, parsed)
|
||||||
|
? textFromValue(std::clamp(parsed, minimum_, maximum_))
|
||||||
|
: textFromValue(value_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LongLongSpinBox::stepBy(int steps)
|
||||||
|
{
|
||||||
|
commitText();
|
||||||
|
qint64 next = value_;
|
||||||
|
if (steps > 0) {
|
||||||
|
const qint64 count = steps;
|
||||||
|
next = singleStep_ > (maximum_ - value_) / count
|
||||||
|
? maximum_ : value_ + singleStep_ * count;
|
||||||
|
} else if (steps < 0) {
|
||||||
|
const qint64 count = -qint64(steps);
|
||||||
|
next = singleStep_ > (value_ - minimum_) / count
|
||||||
|
? minimum_ : value_ - singleStep_ * count;
|
||||||
|
}
|
||||||
|
setValue(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
QAbstractSpinBox::StepEnabled LongLongSpinBox::stepEnabled() const
|
||||||
|
{
|
||||||
|
StepEnabled enabled = StepNone;
|
||||||
|
const qint64 current = value();
|
||||||
|
if (current > minimum_)
|
||||||
|
enabled |= StepDownEnabled;
|
||||||
|
if (current < maximum_)
|
||||||
|
enabled |= StepUpEnabled;
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LongLongSpinBox::textFromValue(qint64 value) const
|
||||||
|
{
|
||||||
|
if (value == minimum_ && !specialValueText_.isEmpty())
|
||||||
|
return specialValueText_;
|
||||||
|
return QString::number(value) + suffix_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LongLongSpinBox::valueFromText(const QString &text, qint64 &value) const
|
||||||
|
{
|
||||||
|
if (!specialValueText_.isEmpty() && text == specialValueText_) {
|
||||||
|
value = minimum_;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
QString number = text;
|
||||||
|
if (!suffix_.isEmpty() && number.endsWith(suffix_))
|
||||||
|
number.chop(suffix_.size());
|
||||||
|
bool ok = false;
|
||||||
|
const qint64 parsed = number.trimmed().toLongLong(&ok);
|
||||||
|
if (ok)
|
||||||
|
value = parsed;
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LongLongSpinBox::commitText()
|
||||||
|
{
|
||||||
|
setValue(value());
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractSpinBox>
|
||||||
|
#include <QValidator>
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
class LongLongSpinBox final : public QAbstractSpinBox {
|
||||||
|
public:
|
||||||
|
explicit LongLongSpinBox(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
qint64 value() const;
|
||||||
|
void setValue(qint64 value);
|
||||||
|
void setRange(qint64 minimum, qint64 maximum);
|
||||||
|
void setSingleStep(qint64 step);
|
||||||
|
void setSuffix(const QString &suffix);
|
||||||
|
void setSpecialValueText(const QString &text);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QValidator::State validate(QString &input, int &position) const override;
|
||||||
|
void fixup(QString &input) const override;
|
||||||
|
void stepBy(int steps) override;
|
||||||
|
StepEnabled stepEnabled() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString textFromValue(qint64 value) const;
|
||||||
|
bool valueFromText(const QString &text, qint64 &value) const;
|
||||||
|
void commitText();
|
||||||
|
|
||||||
|
qint64 minimum_ = 0;
|
||||||
|
qint64 maximum_ = std::numeric_limits<qint64>::max();
|
||||||
|
qint64 value_ = 0;
|
||||||
|
qint64 singleStep_ = 1;
|
||||||
|
QString suffix_;
|
||||||
|
QString specialValueText_;
|
||||||
|
};
|
||||||
+433
-252
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,202 @@
|
|||||||
|
#include "search_core.h"
|
||||||
|
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
|
QStringList patterns(const QString &text)
|
||||||
|
{
|
||||||
|
QStringList out;
|
||||||
|
QString item;
|
||||||
|
bool quoted = false;
|
||||||
|
for (QChar ch : text) {
|
||||||
|
if (ch == u'"') {
|
||||||
|
quoted = !quoted;
|
||||||
|
} else if (!quoted && (ch == u';' || ch == u',')) {
|
||||||
|
if (!item.trimmed().isEmpty())
|
||||||
|
out.push_back(item.trimmed());
|
||||||
|
item.clear();
|
||||||
|
} else {
|
||||||
|
item += ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!item.trimmed().isEmpty())
|
||||||
|
out.push_back(item.trimmed());
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList exclusionPatterns(const QString &text)
|
||||||
|
{
|
||||||
|
QString normalized = text;
|
||||||
|
normalized.replace(QRegularExpression(QStringLiteral("\\s+")), QStringLiteral(";"));
|
||||||
|
QStringList result = patterns(normalized);
|
||||||
|
for (QString &pattern : result) {
|
||||||
|
if (!pattern.contains(u'*') && !pattern.contains(u'?') && !pattern.contains(u'/'))
|
||||||
|
pattern = QStringLiteral("*.") + pattern.remove(QRegularExpression(QStringLiteral("^\\.")));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wildcardMatch(const QString &value, const QStringList &items, Qt::CaseSensitivity cs)
|
||||||
|
{
|
||||||
|
for (const QString &pattern : items) {
|
||||||
|
const auto regex = QRegularExpression(
|
||||||
|
QRegularExpression::wildcardToRegularExpression(pattern),
|
||||||
|
cs == Qt::CaseInsensitive ? QRegularExpression::CaseInsensitiveOption
|
||||||
|
: QRegularExpression::NoPatternOption);
|
||||||
|
if (regex.match(value).hasMatch())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool shouldShowDuplicateResult(bool copiesOnly, int keeperPriority)
|
||||||
|
{
|
||||||
|
if (keeperPriority < 1)
|
||||||
|
return false;
|
||||||
|
return !copiesOnly || keeperPriority > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString humanSize(qint64 bytes)
|
||||||
|
{
|
||||||
|
static const QStringList units{QStringLiteral("B"), QStringLiteral("KB"),
|
||||||
|
QStringLiteral("MB"), QStringLiteral("GB"),
|
||||||
|
QStringLiteral("TB")};
|
||||||
|
double value = static_cast<double>(bytes);
|
||||||
|
int unit = 0;
|
||||||
|
while (value >= 1024.0 && unit < units.size() - 1) {
|
||||||
|
value /= 1024.0;
|
||||||
|
++unit;
|
||||||
|
}
|
||||||
|
return unit == 0 ? QStringLiteral("%1 B").arg(bytes)
|
||||||
|
: QStringLiteral("%1 %2").arg(value, 0, 'f', 2).arg(units[unit]);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ownerName(uid_t uid)
|
||||||
|
{
|
||||||
|
struct passwd pwd {};
|
||||||
|
struct passwd *result = nullptr;
|
||||||
|
QByteArray buffer(16384, Qt::Uninitialized);
|
||||||
|
if (getpwuid_r(uid, &pwd, buffer.data(), static_cast<size_t>(buffer.size()), &result) == 0 && result)
|
||||||
|
return QString::fromLocal8Bit(result->pw_name);
|
||||||
|
return QString::number(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<QByteArray> hexNeedle(QString text)
|
||||||
|
{
|
||||||
|
text.remove(QRegularExpression(QStringLiteral("\\s+")));
|
||||||
|
if (text.size() % 2 != 0 || !QRegularExpression(QStringLiteral("^[0-9a-fA-F]*$")).match(text).hasMatch())
|
||||||
|
return std::nullopt;
|
||||||
|
return QByteArray::fromHex(text.toLatin1());
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
bool isCancelled(const std::atomic_bool *cancelled)
|
||||||
|
{
|
||||||
|
return cancelled && cancelled->load(std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fileContains(const QString &path, const SearchOptions &options,
|
||||||
|
const std::atomic_bool *cancelled)
|
||||||
|
{
|
||||||
|
if (isCancelled(cancelled))
|
||||||
|
return false;
|
||||||
|
if (options.contains.isEmpty())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const QStringList terms = options.multipleValues
|
||||||
|
? patterns(options.contains) : QStringList{options.contains};
|
||||||
|
QList<QByteArray> needles;
|
||||||
|
for (const QString &term : terms) {
|
||||||
|
if (options.binary) {
|
||||||
|
const auto bytes = hexNeedle(term);
|
||||||
|
if (!bytes)
|
||||||
|
return false;
|
||||||
|
needles.push_back(*bytes);
|
||||||
|
} else {
|
||||||
|
needles.push_back(term.toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needles.isEmpty())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
QFile file(path);
|
||||||
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QVector<bool> found(needles.size(), false);
|
||||||
|
qsizetype overlap = 1;
|
||||||
|
for (const QByteArray &needle : needles)
|
||||||
|
overlap = std::max(overlap, needle.size());
|
||||||
|
QByteArray tail;
|
||||||
|
while (!file.atEnd() && !isCancelled(cancelled)) {
|
||||||
|
QByteArray data = tail + file.read(1024 * 1024);
|
||||||
|
if (!options.caseSensitive && !options.binary)
|
||||||
|
data = data.toLower();
|
||||||
|
for (qsizetype i = 0; i < needles.size(); ++i) {
|
||||||
|
QByteArray needle = needles[i];
|
||||||
|
if (!options.caseSensitive && !options.binary)
|
||||||
|
needle = needle.toLower();
|
||||||
|
if (!found[i] && data.contains(needle))
|
||||||
|
found[i] = true;
|
||||||
|
}
|
||||||
|
const bool matched = options.multipleAnd
|
||||||
|
? std::all_of(found.cbegin(), found.cend(), [](bool foundTerm) { return foundTerm; })
|
||||||
|
: std::any_of(found.cbegin(), found.cend(), [](bool foundTerm) { return foundTerm; });
|
||||||
|
if (matched)
|
||||||
|
return true;
|
||||||
|
tail = data.right(overlap - 1);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool filesEqual(const QString &leftPath, const QString &rightPath,
|
||||||
|
const std::atomic_bool *cancelled)
|
||||||
|
{
|
||||||
|
if (isCancelled(cancelled))
|
||||||
|
return false;
|
||||||
|
QFile left(leftPath);
|
||||||
|
QFile right(rightPath);
|
||||||
|
if (!left.open(QIODevice::ReadOnly) || !right.open(QIODevice::ReadOnly)
|
||||||
|
|| left.size() != right.size())
|
||||||
|
return false;
|
||||||
|
while (!left.atEnd() && !isCancelled(cancelled)) {
|
||||||
|
const QByteArray leftData = left.read(1024 * 1024);
|
||||||
|
const QByteArray rightData = right.read(leftData.size());
|
||||||
|
if (leftData != rightData)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !isCancelled(cancelled) && right.atEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray sha256(const QString &path, const std::atomic_bool *cancelled)
|
||||||
|
{
|
||||||
|
if (isCancelled(cancelled))
|
||||||
|
return {};
|
||||||
|
QFile file(path);
|
||||||
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
|
return {};
|
||||||
|
QCryptographicHash hash(QCryptographicHash::Sha256);
|
||||||
|
while (!file.atEnd() && !isCancelled(cancelled))
|
||||||
|
hash.addData(file.read(1024 * 1024));
|
||||||
|
return isCancelled(cancelled) ? QByteArray{} : hash.result();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseOptionalIsoDate(const QString &text, qint64 &seconds)
|
||||||
|
{
|
||||||
|
const QString trimmed = text.trimmed();
|
||||||
|
if (trimmed.isEmpty()) {
|
||||||
|
seconds = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const QDateTime parsed = QDateTime::fromString(trimmed, Qt::ISODate);
|
||||||
|
if (!parsed.isValid())
|
||||||
|
return false;
|
||||||
|
seconds = parsed.toSecsSinceEpoch();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QMetaType>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <optional>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
struct SearchOptions {
|
||||||
|
QString roots = QDir::homePath();
|
||||||
|
QString fileWildcards = QStringLiteral("*");
|
||||||
|
QString subfolderWildcards = QStringLiteral("*");
|
||||||
|
QString excludeFiles;
|
||||||
|
QString excludeFolders;
|
||||||
|
QString includeFolders;
|
||||||
|
QString contains;
|
||||||
|
bool binary = false;
|
||||||
|
bool multipleValues = false;
|
||||||
|
bool multipleAnd = false;
|
||||||
|
bool caseSensitive = false;
|
||||||
|
qint64 minSize = 0;
|
||||||
|
qint64 maxSize = 0;
|
||||||
|
qint64 minTime = 0;
|
||||||
|
qint64 maxTime = 0;
|
||||||
|
QString timeField = QStringLiteral("Modified time");
|
||||||
|
int lastMinutes = 0;
|
||||||
|
bool recursive = true;
|
||||||
|
bool findFiles = true;
|
||||||
|
bool findFolders = false;
|
||||||
|
bool followLinks = false;
|
||||||
|
bool retrieveOwner = false;
|
||||||
|
bool accurateProgress = true;
|
||||||
|
bool useCache = true;
|
||||||
|
int maxDepth = 0;
|
||||||
|
int maxResults = 0;
|
||||||
|
QString mode = QStringLiteral("Standard search");
|
||||||
|
QString duplicateNameMode = QStringLiteral("All files and folders");
|
||||||
|
bool duplicateNameWithoutExtension = false;
|
||||||
|
bool showDuplicateCopiesOnly = true;
|
||||||
|
bool includeSubfoldersInSummary = false;
|
||||||
|
QString hidden = QStringLiteral("Any");
|
||||||
|
QString readonly = QStringLiteral("Any");
|
||||||
|
QString executable = QStringLiteral("Any");
|
||||||
|
|
||||||
|
bool operator==(const SearchOptions &) const = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FileRecord {
|
||||||
|
QString path;
|
||||||
|
QString name;
|
||||||
|
QString folder;
|
||||||
|
qint64 size = 0;
|
||||||
|
qint64 sizeOnDisk = 0;
|
||||||
|
qint64 modified = 0;
|
||||||
|
qint64 created = 0;
|
||||||
|
qint64 accessed = 0;
|
||||||
|
qint64 changed = 0;
|
||||||
|
QString type;
|
||||||
|
QString owner;
|
||||||
|
QString attributes;
|
||||||
|
int group = 0;
|
||||||
|
int duplicateCopy = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(SearchOptions)
|
||||||
|
Q_DECLARE_METATYPE(FileRecord)
|
||||||
|
Q_DECLARE_METATYPE(QVector<FileRecord>)
|
||||||
|
|
||||||
|
QStringList patterns(const QString &text);
|
||||||
|
QStringList exclusionPatterns(const QString &text);
|
||||||
|
bool wildcardMatch(const QString &value, const QStringList &items, Qt::CaseSensitivity cs);
|
||||||
|
QString humanSize(qint64 bytes);
|
||||||
|
QString ownerName(uid_t uid);
|
||||||
|
std::optional<QByteArray> hexNeedle(QString text);
|
||||||
|
bool fileContains(const QString &path, const SearchOptions &options,
|
||||||
|
const std::atomic_bool *cancelled = nullptr);
|
||||||
|
bool filesEqual(const QString &leftPath, const QString &rightPath,
|
||||||
|
const std::atomic_bool *cancelled = nullptr);
|
||||||
|
QByteArray sha256(const QString &path, const std::atomic_bool *cancelled = nullptr);
|
||||||
|
bool parseOptionalIsoDate(const QString &text, qint64 &seconds);
|
||||||
|
bool shouldShowDuplicateResult(bool copiesOnly, int keeperPriority);
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#include "long_long_spin_box.h"
|
||||||
|
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
class LongLongSpinBoxTest final : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void preservesValuesAboveTwoGigabytes()
|
||||||
|
{
|
||||||
|
LongLongSpinBox spin;
|
||||||
|
spin.setRange(0, std::numeric_limits<qint64>::max());
|
||||||
|
spin.setSuffix(QStringLiteral(" bytes"));
|
||||||
|
spin.setValue(5'000'000'000);
|
||||||
|
QCOMPARE(spin.value(), qint64(5'000'000'000));
|
||||||
|
QCOMPARE(spin.findChild<QLineEdit *>()->text(), QStringLiteral("5000000000 bytes"));
|
||||||
|
spin.stepUp();
|
||||||
|
QCOMPARE(spin.value(), qint64(5'000'000'001));
|
||||||
|
|
||||||
|
spin.findChild<QLineEdit *>()->setText(QStringLiteral("6000000000 bytes"));
|
||||||
|
QVERIFY(QMetaObject::invokeMethod(&spin, "editingFinished", Qt::DirectConnection));
|
||||||
|
QCOMPARE(spin.value(), qint64(6'000'000'000));
|
||||||
|
}
|
||||||
|
|
||||||
|
void clampsAtRangeEdges()
|
||||||
|
{
|
||||||
|
LongLongSpinBox spin;
|
||||||
|
spin.setRange(0, 10);
|
||||||
|
spin.setValue(10);
|
||||||
|
spin.stepUp();
|
||||||
|
QCOMPARE(spin.value(), qint64(10));
|
||||||
|
spin.setValue(-50);
|
||||||
|
QCOMPARE(spin.value(), qint64(0));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
QTEST_MAIN(LongLongSpinBoxTest)
|
||||||
|
|
||||||
|
#include "long_long_spin_box_test.moc"
|
||||||
Executable
+20
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
release_script="$(realpath "$1")"
|
||||||
|
test_directory="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$test_directory"' EXIT
|
||||||
|
|
||||||
|
git -C "$test_directory" init -q
|
||||||
|
git -C "$test_directory" config user.name "FolderScope Tests"
|
||||||
|
git -C "$test_directory" config user.email "tests@folderscope.invalid"
|
||||||
|
printf '9.9.9\n' > "$test_directory/VERSION"
|
||||||
|
printf '# Changelog\n\n## [9.9.9]\n' > "$test_directory/CHANGELOG.md"
|
||||||
|
git -C "$test_directory" add VERSION CHANGELOG.md
|
||||||
|
git -C "$test_directory" commit -q -m "test fixture"
|
||||||
|
touch "$test_directory/untracked"
|
||||||
|
|
||||||
|
if (cd "$test_directory" && "$release_script" 9.9.9 >/dev/null 2>&1); then
|
||||||
|
echo "release.sh accepted a repository with untracked files" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
#include "search_core.h"
|
||||||
|
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTemporaryDir>
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
class SearchCoreTest final : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void parsesPatternsAndExclusions()
|
||||||
|
{
|
||||||
|
QCOMPARE(patterns(QStringLiteral("/a; \"/b,with-comma\" , /c")),
|
||||||
|
QStringList({QStringLiteral("/a"), QStringLiteral("/b,with-comma"),
|
||||||
|
QStringLiteral("/c")}));
|
||||||
|
QCOMPARE(exclusionPatterns(QStringLiteral("tmp log *.bak")),
|
||||||
|
QStringList({QStringLiteral("*.tmp"), QStringLiteral("*.log"),
|
||||||
|
QStringLiteral("*.bak")}));
|
||||||
|
QVERIFY(wildcardMatch(QStringLiteral("Report.TXT"), {QStringLiteral("*.txt")},
|
||||||
|
Qt::CaseInsensitive));
|
||||||
|
QVERIFY(!wildcardMatch(QStringLiteral("Report.TXT"), {QStringLiteral("*.txt")},
|
||||||
|
Qt::CaseSensitive));
|
||||||
|
}
|
||||||
|
|
||||||
|
void parsesOptionalIsoDates()
|
||||||
|
{
|
||||||
|
qint64 seconds = -1;
|
||||||
|
QVERIFY(parseOptionalIsoDate(QString{}, seconds));
|
||||||
|
QCOMPARE(seconds, 0);
|
||||||
|
QVERIFY(parseOptionalIsoDate(QStringLiteral("2026-07-25T20:30:00"), seconds));
|
||||||
|
QVERIFY(seconds > 0);
|
||||||
|
QVERIFY(!parseOptionalIsoDate(QStringLiteral("2026-not-a-date"), seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
void selectsDuplicateRowsForDisplay()
|
||||||
|
{
|
||||||
|
QVERIFY(!shouldShowDuplicateResult(true, 0));
|
||||||
|
QVERIFY(!shouldShowDuplicateResult(true, 1));
|
||||||
|
QVERIFY(shouldShowDuplicateResult(true, 2));
|
||||||
|
|
||||||
|
QVERIFY(!shouldShowDuplicateResult(false, 0));
|
||||||
|
QVERIFY(shouldShowDuplicateResult(false, 1));
|
||||||
|
QVERIFY(shouldShowDuplicateResult(false, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void searchesContentsAndHashes()
|
||||||
|
{
|
||||||
|
QTemporaryDir directory;
|
||||||
|
QVERIFY(directory.isValid());
|
||||||
|
const QString firstPath = directory.filePath(QStringLiteral("first.bin"));
|
||||||
|
const QString secondPath = directory.filePath(QStringLiteral("second.bin"));
|
||||||
|
const QString differentPath = directory.filePath(QStringLiteral("different.bin"));
|
||||||
|
const QByteArray content = QByteArray(1024 * 1024 - 2, 'x')
|
||||||
|
+ QByteArray("Alpha needle BETA");
|
||||||
|
|
||||||
|
QFile first(firstPath);
|
||||||
|
QVERIFY(first.open(QIODevice::WriteOnly));
|
||||||
|
QCOMPARE(first.write(content), content.size());
|
||||||
|
first.close();
|
||||||
|
|
||||||
|
QFile second(secondPath);
|
||||||
|
QVERIFY(second.open(QIODevice::WriteOnly));
|
||||||
|
QCOMPARE(second.write(content), content.size());
|
||||||
|
second.close();
|
||||||
|
|
||||||
|
QFile different(differentPath);
|
||||||
|
QVERIFY(different.open(QIODevice::WriteOnly));
|
||||||
|
QCOMPARE(different.write("different"), qint64(9));
|
||||||
|
different.close();
|
||||||
|
|
||||||
|
SearchOptions options;
|
||||||
|
options.contains = QStringLiteral("needle");
|
||||||
|
QVERIFY(fileContains(firstPath, options));
|
||||||
|
options.contains = QStringLiteral("alpha,beta");
|
||||||
|
options.multipleValues = true;
|
||||||
|
options.multipleAnd = true;
|
||||||
|
QVERIFY(fileContains(firstPath, options));
|
||||||
|
options.caseSensitive = true;
|
||||||
|
QVERIFY(!fileContains(firstPath, options));
|
||||||
|
options.binary = true;
|
||||||
|
options.multipleValues = false;
|
||||||
|
options.multipleAnd = false;
|
||||||
|
options.contains = QStringLiteral("41 6c 70 68 61");
|
||||||
|
QVERIFY(fileContains(firstPath, options));
|
||||||
|
options.contains = QStringLiteral("ABC");
|
||||||
|
QVERIFY(!fileContains(firstPath, options));
|
||||||
|
|
||||||
|
QVERIFY(filesEqual(firstPath, secondPath));
|
||||||
|
QVERIFY(!filesEqual(firstPath, differentPath));
|
||||||
|
QCOMPARE(sha256(firstPath), QCryptographicHash::hash(content, QCryptographicHash::Sha256));
|
||||||
|
}
|
||||||
|
|
||||||
|
void cancelsFileOperations()
|
||||||
|
{
|
||||||
|
QTemporaryDir directory;
|
||||||
|
QVERIFY(directory.isValid());
|
||||||
|
const QString path = directory.filePath(QStringLiteral("file.bin"));
|
||||||
|
QFile file(path);
|
||||||
|
QVERIFY(file.open(QIODevice::WriteOnly));
|
||||||
|
QCOMPARE(file.write("needle"), qint64(6));
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
std::atomic_bool cancelled = true;
|
||||||
|
SearchOptions options;
|
||||||
|
options.contains = QStringLiteral("needle");
|
||||||
|
QVERIFY(!fileContains(path, options, &cancelled));
|
||||||
|
QVERIFY(!filesEqual(path, path, &cancelled));
|
||||||
|
QVERIFY(sha256(path, &cancelled).isEmpty());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN(SearchCoreTest)
|
||||||
|
|
||||||
|
#include "search_core_test.moc"
|
||||||
Reference in New Issue
Block a user