mirror of
https://github.com/uutils/findutils.git
synced 2026-06-10 15:48:30 -07:00
Compare commits
103 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b94b5f0122 | |||
| 4f8fbf55a1 | |||
| 3dbdbe8442 | |||
| 949bcb83c8 | |||
| 61b396ac31 | |||
| 6c99dc175f | |||
| 778abdb6a9 | |||
| a61993b705 | |||
| bd159d7627 | |||
| ad61338bb2 | |||
| 4a1c683834 | |||
| 2ec695381e | |||
| a04b499e15 | |||
| de42f9bd83 | |||
| 6d264dbbcf | |||
| 81c39aad7d | |||
| 5cb273eecb | |||
| 55021afb69 | |||
| 013be1b093 | |||
| 0429507f15 | |||
| 5235d78291 | |||
| 1a40442f20 | |||
| cb83b6db3a | |||
| e92ebc9288 | |||
| d6dc18973d | |||
| 9fdfb1ee08 | |||
| 830298ed22 | |||
| 8784923b54 | |||
| 89f98f1aff | |||
| f911610d93 | |||
| 22c5f7dcc3 | |||
| f3a70e9eb4 | |||
| 55298be4ad | |||
| 764be30111 | |||
| 6d54482ed4 | |||
| 49975f5c62 | |||
| dacc473c85 | |||
| 5bad2e0afe | |||
| 28b1c88d9c | |||
| c7b89d5341 | |||
| b4c5c4946b | |||
| 16bb731937 | |||
| 6d366cbbda | |||
| 280381bb28 | |||
| 1809a3edca | |||
| 0a54e7c6d9 | |||
| 5d264c9c7b | |||
| d8355d48a3 | |||
| a7b596daef | |||
| 22a58468b8 | |||
| 0f9ca9eace | |||
| a90f505510 | |||
| e32e754102 | |||
| 83dc5fe7de | |||
| cb3f3cfea4 | |||
| 1f9d90eb4f | |||
| 98ce63a65e | |||
| a547d24f46 | |||
| b263b20801 | |||
| 5ae9315c1b | |||
| 87459296e6 | |||
| e9374afc99 | |||
| 1ea16258c3 | |||
| 9226ff10b6 | |||
| 8c93719bfc | |||
| 629f5b793d | |||
| d7ce651130 | |||
| 7be665cbbe | |||
| 5319654dfb | |||
| 145b96871a | |||
| fb4108192c | |||
| e0397917e4 | |||
| 9d1a97768f | |||
| fc3de09ca2 | |||
| 78e520106c | |||
| a21c379953 | |||
| c45e474c7e | |||
| f536f813e2 | |||
| 8685fa5c64 | |||
| b7f93ea816 | |||
| 10c24ca5f1 | |||
| 33cd6573aa | |||
| 6ce5ffaa9e | |||
| 78b264deae | |||
| 3fa75542c4 | |||
| 4e954a7a41 | |||
| 50b7ec67e0 | |||
| b3f4deda63 | |||
| 1b3ad03b1f | |||
| 11a0b64c91 | |||
| 2e9e90887f | |||
| 526079b5d3 | |||
| dce8b2dda5 | |||
| fb7a56be63 | |||
| acbfcc52ca | |||
| b641b85239 | |||
| eefc5804d4 | |||
| 309d3d9211 | |||
| 9d66be6b7d | |||
| 27d95aa1cc | |||
| 05493375c7 | |||
| 7f3c00db69 | |||
| 4d367891dc |
@@ -105,49 +105,24 @@ jobs:
|
||||
|
||||
- name: Install `rust` toolchain
|
||||
run: |
|
||||
## Install `rust` toolchain
|
||||
rustup toolchain install nightly --no-self-update -c rustfmt --profile minimal
|
||||
rustup default nightly
|
||||
|
||||
- name: "`grcov` ~ install"
|
||||
run: cargo install grcov
|
||||
- name: Install cargo-llvm-cov
|
||||
uses: taiki-e/install-action@cargo-llvm-cov
|
||||
- name: Generate code coverage
|
||||
run: cargo llvm-cov --all-features --lcov --branch --output-path lcov.info
|
||||
|
||||
- name: cargo test
|
||||
run: |
|
||||
cargo test --all --no-fail-fast ${{ matrix.cargo_flags }}
|
||||
env:
|
||||
CARGO_INCREMENTAL: "0"
|
||||
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort -Cdebug-assertions=off"
|
||||
RUSTDOCFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort -Cdebug-assertions=off"
|
||||
|
||||
- name: Generate coverage data
|
||||
id: grcov
|
||||
run: |
|
||||
grcov target/debug/ \
|
||||
--branch \
|
||||
--llvm \
|
||||
--source-dir . \
|
||||
--output-path lcov.info \
|
||||
--ignore-not-existing \
|
||||
--excl-line "#\\[derive\\(" \
|
||||
--excl-br-line "#\\[derive\\(" \
|
||||
--excl-start "#\\[cfg\\(test\\)\\]" \
|
||||
--excl-br-start "#\\[cfg\\(test\\)\\]" \
|
||||
--commit-sha ${{ github.sha }} \
|
||||
--service-job-id ${{ github.job }} \
|
||||
--service-name "GitHub Actions" \
|
||||
--service-number ${{ github.run_id }}
|
||||
- name: Upload coverage as artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lcov.info
|
||||
# path: ${{ steps.grcov.outputs.report }}
|
||||
path: lcov.info
|
||||
|
||||
- name: Upload coverage to codecov.io
|
||||
uses: codecov/codecov-action@v4
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
# file: ${{ steps.grcov.outputs.report }}
|
||||
file: lcov.info
|
||||
files: lcov.info
|
||||
fail_ci_if_error: true
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
@@ -4,6 +4,9 @@ name: External-testsuites
|
||||
|
||||
jobs:
|
||||
gnu-tests:
|
||||
permissions:
|
||||
actions: read
|
||||
|
||||
name: Run GNU findutils tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -17,7 +20,15 @@ jobs:
|
||||
repository: gnu-mirror-unofficial/findutils
|
||||
path: findutils.gnu
|
||||
ref: 5768a03ddfb5e18b1682e339d6cdd24ff721c510
|
||||
submodules: true
|
||||
submodules: false
|
||||
|
||||
- name: Override submodule URL and initialize submodules
|
||||
# Use github instead of upstream git server
|
||||
run: |
|
||||
git submodule sync --recursive
|
||||
git config submodule.gnulib.url https://github.com/coreutils/gnulib.git
|
||||
git submodule update --init --recursive --depth 1
|
||||
working-directory: findutils.gnu
|
||||
- name: Install `rust` toolchain
|
||||
run: |
|
||||
## Install `rust` toolchain
|
||||
@@ -27,7 +38,7 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
# Enable sources & install dependencies
|
||||
sudo find /etc/apt/sources.list* -type f -exec sed -i 'p; s/^deb /deb-src /' '{}' +
|
||||
sudo sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
|
||||
sudo apt-get update
|
||||
sudo apt-get build-dep findutils
|
||||
- name: Run GNU tests
|
||||
@@ -38,6 +49,7 @@ jobs:
|
||||
- name: Extract testing info
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
- name: Upload gnu-test-report
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
@@ -51,24 +63,43 @@ jobs:
|
||||
with:
|
||||
name: gnu-result
|
||||
path: gnu-result.json
|
||||
- name: Download the result
|
||||
uses: dawidd6/action-download-artifact@v6
|
||||
- name: Download artifacts (gnu-result and gnu-test-report)
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
workflow: compat.yml
|
||||
workflow_conclusion: completed
|
||||
name: gnu-result
|
||||
repo: uutils/findutils
|
||||
branch: main
|
||||
path: dl
|
||||
- name: Download the log
|
||||
uses: dawidd6/action-download-artifact@v6
|
||||
with:
|
||||
workflow: compat.yml
|
||||
workflow_conclusion: completed
|
||||
name: gnu-test-report
|
||||
repo: uutils/findutils
|
||||
branch: main
|
||||
path: dl
|
||||
script: |
|
||||
let fs = require('fs');
|
||||
fs.mkdirSync('${{ github.workspace }}/dl', { recursive: true });
|
||||
|
||||
async function downloadArtifact(artifactName) {
|
||||
// List all artifacts from the workflow run
|
||||
let artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.run_id }},
|
||||
});
|
||||
|
||||
// Find the specified artifact
|
||||
let matchArtifact = artifacts.data.artifacts.find((artifact) => artifact.name === artifactName);
|
||||
if (!matchArtifact) {
|
||||
throw new Error(`Artifact "${artifactName}" not found.`);
|
||||
}
|
||||
|
||||
// Download the artifact
|
||||
let download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
|
||||
// Save the artifact to a file
|
||||
fs.writeFileSync(`${{ github.workspace }}/dl/${artifactName}.zip`, Buffer.from(download.data));
|
||||
}
|
||||
|
||||
// Download the required artifacts
|
||||
await downloadArtifact("gnu-result");
|
||||
await downloadArtifact("gnu-test-report");
|
||||
|
||||
- name: Compare failing tests against master
|
||||
shell: bash
|
||||
run: |
|
||||
@@ -76,6 +107,8 @@ jobs:
|
||||
- name: Compare against main results
|
||||
shell: bash
|
||||
run: |
|
||||
unzip dl/gnu-result.zip -d dl/
|
||||
unzip dl/gnu-test-report.zip -d dl/
|
||||
mv dl/gnu-result.json latest-gnu-result.json
|
||||
python findutils/util/compare_gnu_result.py
|
||||
|
||||
@@ -102,7 +135,7 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
# Enable sources & install dependencies
|
||||
sudo find /etc/apt/sources.list* -type f -exec sed -i 'p; s/^deb /deb-src /' '{}' +
|
||||
sudo sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
|
||||
sudo apt-get update
|
||||
sudo apt-get build-dep bfs
|
||||
- name: Run BFS tests
|
||||
@@ -120,24 +153,42 @@ jobs:
|
||||
with:
|
||||
name: bfs-result
|
||||
path: bfs-result.json
|
||||
- name: Download the result
|
||||
uses: dawidd6/action-download-artifact@v6
|
||||
- name: Download artifacts (gnu-result and bfs-test-report)
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
workflow: compat.yml
|
||||
workflow_conclusion: completed
|
||||
name: bfs-result
|
||||
repo: uutils/findutils
|
||||
branch: main
|
||||
path: dl
|
||||
- name: Download the log
|
||||
uses: dawidd6/action-download-artifact@v6
|
||||
with:
|
||||
workflow: compat.yml
|
||||
workflow_conclusion: completed
|
||||
name: bfs-test-report
|
||||
repo: uutils/findutils
|
||||
branch: main
|
||||
path: dl
|
||||
script: |
|
||||
let fs = require('fs');
|
||||
fs.mkdirSync('${{ github.workspace }}/dl', { recursive: true });
|
||||
|
||||
async function downloadArtifact(artifactName) {
|
||||
// List all artifacts from the workflow run
|
||||
let artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.run_id }},
|
||||
});
|
||||
|
||||
// Find the specified artifact
|
||||
let matchArtifact = artifacts.data.artifacts.find((artifact) => artifact.name === artifactName);
|
||||
if (!matchArtifact) {
|
||||
throw new Error(`Artifact "${artifactName}" not found.`);
|
||||
}
|
||||
|
||||
// Download the artifact
|
||||
let download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
|
||||
// Save the artifact to a file
|
||||
fs.writeFileSync(`${{ github.workspace }}/dl/${artifactName}.zip`, Buffer.from(download.data));
|
||||
}
|
||||
|
||||
// Download the required artifacts
|
||||
await downloadArtifact("bfs-result");
|
||||
await downloadArtifact("bfs-test-report");
|
||||
- name: Compare failing tests against main
|
||||
shell: bash
|
||||
run: |
|
||||
@@ -145,6 +196,8 @@ jobs:
|
||||
- name: Compare against main results
|
||||
shell: bash
|
||||
run: |
|
||||
unzip dl/bfs-result.zip -d dl/
|
||||
unzip dl/bfs-test-report.zip -d dl/
|
||||
mv dl/bfs-result.json latest-bfs-result.json
|
||||
python findutils/util/compare_bfs_result.py
|
||||
|
||||
@@ -157,7 +210,7 @@ jobs:
|
||||
steps:
|
||||
- name: List Annotations
|
||||
uses: actions/github-script@v7
|
||||
|
||||
|
||||
with:
|
||||
script: |
|
||||
let runs = await github.rest.checks.listForRef({
|
||||
@@ -177,7 +230,7 @@ jobs:
|
||||
repo: context.repo.repo,
|
||||
check_run_id: result.id
|
||||
});
|
||||
|
||||
|
||||
run.data.forEach(data => {
|
||||
annotations.data.push({
|
||||
run: result.name,
|
||||
@@ -187,7 +240,7 @@ jobs:
|
||||
}
|
||||
|
||||
// Remove duplicate items.
|
||||
annotations.data = annotations.data.filter((value, index, self) =>
|
||||
annotations.data = annotations.data.filter((value, index, self) =>
|
||||
self.findIndex(v => v.annotation.message === value.annotation.message) === index);
|
||||
|
||||
let fs = require('fs');
|
||||
@@ -197,4 +250,4 @@ jobs:
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: comment
|
||||
path: annotations.json
|
||||
path: annotations.json
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
# Copyright 2022-2023, axodotdev
|
||||
# This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/
|
||||
#
|
||||
# Copyright 2022-2024, axodotdev
|
||||
# SPDX-License-Identifier: MIT or Apache-2.0
|
||||
#
|
||||
# CI that:
|
||||
#
|
||||
# * checks for a Git Tag that looks like a release
|
||||
# * builds artifacts with cargo-dist (archives, installers, hashes)
|
||||
# * builds artifacts with dist (archives, installers, hashes)
|
||||
# * uploads those artifacts to temporary workflow zip
|
||||
# * on success, uploads the artifacts to a Github Release
|
||||
# * on success, uploads the artifacts to a GitHub Release
|
||||
#
|
||||
# Note that the Github Release will be created with a generated
|
||||
# Note that the GitHub Release will be created with a generated
|
||||
# title/body based on your changelogs.
|
||||
|
||||
name: Release
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
"contents": "write"
|
||||
|
||||
# This task will run whenever you push a git tag that looks like a version
|
||||
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
|
||||
@@ -23,30 +24,30 @@ permissions:
|
||||
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
|
||||
#
|
||||
# If PACKAGE_NAME is specified, then the announcement will be for that
|
||||
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
|
||||
# package (erroring out if it doesn't have the given version or isn't dist-able).
|
||||
#
|
||||
# If PACKAGE_NAME isn't specified, then the announcement will be for all
|
||||
# (cargo-dist-able) packages in the workspace with that version (this mode is
|
||||
# (dist-able) packages in the workspace with that version (this mode is
|
||||
# intended for workspaces with only one dist-able package, or with all dist-able
|
||||
# packages versioned/released in lockstep).
|
||||
#
|
||||
# If you push multiple tags at once, separate instances of this workflow will
|
||||
# spin up, creating an independent announcement for each one. However Github
|
||||
# spin up, creating an independent announcement for each one. However, GitHub
|
||||
# will hard limit this to 3 tags per commit, as it will assume more tags is a
|
||||
# mistake.
|
||||
#
|
||||
# If there's a prerelease-style suffix to the version, then the release(s)
|
||||
# will be marked as a prerelease.
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
tags:
|
||||
- '**[0-9]+.[0-9]+.[0-9]+*'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
|
||||
# Run 'dist plan' (or host) to determine what tasks we need to do
|
||||
plan:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: "ubuntu-20.04"
|
||||
outputs:
|
||||
val: ${{ steps.plan.outputs.manifest }}
|
||||
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
|
||||
@@ -58,11 +59,16 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install cargo-dist
|
||||
- name: Install dist
|
||||
# we specify bash to get pipefail; it guards against the `curl` command
|
||||
# failing. otherwise `sh` won't catch that `curl` returned non-0
|
||||
shell: bash
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.28.0/cargo-dist-installer.sh | sh"
|
||||
- name: Cache dist
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: cargo-dist-cache
|
||||
path: ~/.cargo/bin/dist
|
||||
# sure would be cool if github gave us proper conditionals...
|
||||
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
|
||||
# functionality based on whether this is a pull_request, and whether it's from a fork.
|
||||
@@ -70,8 +76,8 @@ jobs:
|
||||
# but also really annoying to build CI around when it needs secrets to work right.)
|
||||
- id: plan
|
||||
run: |
|
||||
cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
|
||||
echo "cargo dist ran successfully"
|
||||
dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
|
||||
echo "dist ran successfully"
|
||||
cat plan-dist-manifest.json
|
||||
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
|
||||
- name: "Upload dist-manifest.json"
|
||||
@@ -89,28 +95,38 @@ jobs:
|
||||
if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
# Target platforms/runners are computed by cargo-dist in create-release.
|
||||
# Target platforms/runners are computed by dist in create-release.
|
||||
# Each member of the matrix has the following arguments:
|
||||
#
|
||||
# - runner: the github runner
|
||||
# - dist-args: cli flags to pass to cargo dist
|
||||
# - install-dist: expression to run to install cargo-dist on the runner
|
||||
# - dist-args: cli flags to pass to dist
|
||||
# - install-dist: expression to run to install dist on the runner
|
||||
#
|
||||
# Typically there will be:
|
||||
# - 1 "global" task that builds universal installers
|
||||
# - N "local" tasks that build each platform's binaries and platform-specific installers
|
||||
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
|
||||
runs-on: ${{ matrix.runner }}
|
||||
container: ${{ matrix.container && matrix.container.image || null }}
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
|
||||
steps:
|
||||
- name: enable windows longpaths
|
||||
run: |
|
||||
git config --global core.longpaths true
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- name: Install cargo-dist
|
||||
run: ${{ matrix.install_dist }}
|
||||
- name: Install Rust non-interactively if not already installed
|
||||
if: ${{ matrix.container }}
|
||||
run: |
|
||||
if ! command -v cargo > /dev/null 2>&1; then
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
fi
|
||||
- name: Install dist
|
||||
run: ${{ matrix.install_dist.run }}
|
||||
# Get the dist-manifest
|
||||
- name: Fetch local artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -124,8 +140,8 @@ jobs:
|
||||
- name: Build artifacts
|
||||
run: |
|
||||
# Actually do builds and make zips and whatnot
|
||||
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
|
||||
echo "cargo dist ran successfully"
|
||||
dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
|
||||
echo "dist ran successfully"
|
||||
- id: cargo-dist
|
||||
name: Post-build
|
||||
# We force bash here just because github makes it really hard to get values up
|
||||
@@ -135,7 +151,7 @@ jobs:
|
||||
run: |
|
||||
# Parse out what we just built and upload it to scratch storage
|
||||
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
|
||||
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
|
||||
dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
|
||||
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
|
||||
@@ -160,9 +176,12 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install cargo-dist
|
||||
shell: bash
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
|
||||
- name: Install cached dist
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: cargo-dist-cache
|
||||
path: ~/.cargo/bin/
|
||||
- run: chmod +x ~/.cargo/bin/dist
|
||||
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
|
||||
- name: Fetch local artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -173,12 +192,12 @@ jobs:
|
||||
- id: cargo-dist
|
||||
shell: bash
|
||||
run: |
|
||||
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
|
||||
echo "cargo dist ran successfully"
|
||||
dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
|
||||
echo "dist ran successfully"
|
||||
|
||||
# Parse out what we just built and upload it to scratch storage
|
||||
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
|
||||
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
|
||||
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
|
||||
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
|
||||
@@ -206,8 +225,12 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install cargo-dist
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
|
||||
- name: Install cached dist
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: cargo-dist-cache
|
||||
path: ~/.cargo/bin/
|
||||
- run: chmod +x ~/.cargo/bin/dist
|
||||
# Fetch artifacts from scratch-storage
|
||||
- name: Fetch artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -215,11 +238,10 @@ jobs:
|
||||
pattern: artifacts-*
|
||||
path: target/distrib/
|
||||
merge-multiple: true
|
||||
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
|
||||
- id: host
|
||||
shell: bash
|
||||
run: |
|
||||
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
|
||||
dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
|
||||
echo "artifacts uploaded and released successfully"
|
||||
cat dist-manifest.json
|
||||
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
|
||||
@@ -229,8 +251,29 @@ jobs:
|
||||
# Overwrite the previous copy
|
||||
name: artifacts-dist-manifest
|
||||
path: dist-manifest.json
|
||||
# Create a GitHub Release while uploading all files to it
|
||||
- name: "Download GitHub Artifacts"
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: artifacts-*
|
||||
path: artifacts
|
||||
merge-multiple: true
|
||||
- name: Cleanup
|
||||
run: |
|
||||
# Remove the granular manifests
|
||||
rm -f artifacts/*-dist-manifest.json
|
||||
- name: Create GitHub Release
|
||||
env:
|
||||
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
|
||||
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
|
||||
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
|
||||
RELEASE_COMMIT: "${{ github.sha }}"
|
||||
run: |
|
||||
# Write and read notes from a file to avoid quoting breaking things
|
||||
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
|
||||
|
||||
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
|
||||
|
||||
# Create a Github Release while uploading all files to it
|
||||
announce:
|
||||
needs:
|
||||
- plan
|
||||
@@ -246,21 +289,3 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: "Download Github Artifacts"
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: artifacts-*
|
||||
path: artifacts
|
||||
merge-multiple: true
|
||||
- name: Cleanup
|
||||
run: |
|
||||
# Remove the granular manifests
|
||||
rm -f artifacts/*-dist-manifest.json
|
||||
- name: Create Github Release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
tag: ${{ needs.plan.outputs.tag }}
|
||||
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
|
||||
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
|
||||
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
|
||||
artifacts: "artifacts/*"
|
||||
|
||||
Generated
+295
-187
File diff suppressed because it is too large
Load Diff
+23
-24
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "findutils"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
homepage = "https://github.com/uutils/findutils"
|
||||
repository = "https://github.com/uutils/findutils"
|
||||
edition = "2021"
|
||||
@@ -10,24 +10,24 @@ description = "Rust implementation of GNU findutils"
|
||||
authors = ["uutils developers"]
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.38"
|
||||
chrono = "0.4.40"
|
||||
clap = "4.5"
|
||||
faccess = "0.2.4"
|
||||
walkdir = "2.5"
|
||||
regex = "1.10"
|
||||
once_cell = "1.19"
|
||||
regex = "1.11"
|
||||
onig = { version = "6.4", default-features = false }
|
||||
uucore = { version = "0.0.27", features = ["entries", "fs", "fsext", "mode"] }
|
||||
uucore = { version = "0.0.30", features = ["entries", "fs", "fsext", "mode"] }
|
||||
nix = { version = "0.29", features = ["fs", "user"] }
|
||||
argmax = "0.3.1"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2"
|
||||
filetime = "0.2"
|
||||
nix = { version = "0.29", features = ["fs"] }
|
||||
predicates = "3"
|
||||
serial_test = "3.1"
|
||||
serial_test = "3.2"
|
||||
tempfile = "3"
|
||||
pretty_assertions = "1.4.0"
|
||||
pretty_assertions = "1.4.1"
|
||||
|
||||
[[bin]]
|
||||
name = "find"
|
||||
@@ -46,20 +46,19 @@ path = "src/testing/commandline/main.rs"
|
||||
inherits = "release"
|
||||
lto = "thin"
|
||||
|
||||
# Config for 'cargo dist'
|
||||
[workspace.metadata.dist]
|
||||
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
|
||||
cargo-dist-version = "0.12.0"
|
||||
# CI backends to support
|
||||
ci = ["github"]
|
||||
# The installers to generate for each app
|
||||
installers = []
|
||||
# Target platforms to build apps for (Rust target-triple syntax)
|
||||
targets = [
|
||||
"aarch64-apple-darwin",
|
||||
"x86_64-apple-darwin",
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"x86_64-pc-windows-msvc",
|
||||
]
|
||||
# Publish jobs to run in CI
|
||||
pr-run-mode = "plan"
|
||||
|
||||
[lints.clippy]
|
||||
multiple_crate_versions = "allow"
|
||||
cargo_common_metadata = "allow"
|
||||
uninlined_format_args = "allow"
|
||||
missing_panics_doc = "allow"
|
||||
|
||||
use_self = "warn"
|
||||
needless_pass_by_value = "warn"
|
||||
semicolon_if_nothing_returned = "warn"
|
||||
single_char_pattern = "warn"
|
||||
explicit_iter_loop = "warn"
|
||||
if_not_else = "warn"
|
||||
manual_let_else = "warn"
|
||||
# Disable for now, we have a few occurrences
|
||||
# panic = "warn"
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[workspace]
|
||||
members = ["cargo:."]
|
||||
|
||||
# Config for 'dist'
|
||||
[dist]
|
||||
# The preferred dist version to use in CI (Cargo.toml SemVer syntax)
|
||||
cargo-dist-version = "0.28.0"
|
||||
# CI backends to support
|
||||
ci = "github"
|
||||
# The installers to generate for each app
|
||||
installers = ["shell"]
|
||||
# Target platforms to build apps for (Rust target-triple syntax)
|
||||
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
|
||||
# Which actions to run on pull requests
|
||||
pr-run-mode = "plan"
|
||||
# Path that installers should place binaries in
|
||||
install-path = "CARGO_HOME"
|
||||
# Whether to install an updater program
|
||||
install-updater = false
|
||||
@@ -16,7 +16,7 @@ pub struct DeleteMatcher;
|
||||
|
||||
impl DeleteMatcher {
|
||||
pub fn new() -> Self {
|
||||
DeleteMatcher
|
||||
Self
|
||||
}
|
||||
|
||||
fn delete(&self, entry: &WalkEntry) -> io::Result<()> {
|
||||
|
||||
@@ -14,8 +14,8 @@ use super::{Matcher, MatcherIO, WalkEntry};
|
||||
pub struct EmptyMatcher;
|
||||
|
||||
impl EmptyMatcher {
|
||||
pub fn new() -> EmptyMatcher {
|
||||
EmptyMatcher
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+24
-24
@@ -51,34 +51,34 @@ impl FileType {
|
||||
}
|
||||
|
||||
impl From<fs::FileType> for FileType {
|
||||
fn from(t: fs::FileType) -> FileType {
|
||||
fn from(t: fs::FileType) -> Self {
|
||||
if t.is_dir() {
|
||||
return FileType::Directory;
|
||||
return Self::Directory;
|
||||
}
|
||||
if t.is_file() {
|
||||
return FileType::Regular;
|
||||
return Self::Regular;
|
||||
}
|
||||
if t.is_symlink() {
|
||||
return FileType::Symlink;
|
||||
return Self::Symlink;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if t.is_fifo() {
|
||||
return FileType::Fifo;
|
||||
return Self::Fifo;
|
||||
}
|
||||
if t.is_char_device() {
|
||||
return FileType::CharDevice;
|
||||
return Self::CharDevice;
|
||||
}
|
||||
if t.is_block_device() {
|
||||
return FileType::BlockDevice;
|
||||
return Self::BlockDevice;
|
||||
}
|
||||
if t.is_socket() {
|
||||
return FileType::Socket;
|
||||
return Self::Socket;
|
||||
}
|
||||
}
|
||||
|
||||
FileType::Unknown
|
||||
Self::Unknown
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,14 +150,14 @@ impl Display for WalkError {
|
||||
impl Error for WalkError {}
|
||||
|
||||
impl From<io::Error> for WalkError {
|
||||
fn from(e: io::Error) -> WalkError {
|
||||
WalkError::from(&e)
|
||||
fn from(e: io::Error) -> Self {
|
||||
Self::from(&e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&io::Error> for WalkError {
|
||||
fn from(e: &io::Error) -> WalkError {
|
||||
WalkError {
|
||||
fn from(e: &io::Error) -> Self {
|
||||
Self {
|
||||
path: None,
|
||||
depth: None,
|
||||
raw: e.raw_os_error(),
|
||||
@@ -166,14 +166,14 @@ impl From<&io::Error> for WalkError {
|
||||
}
|
||||
|
||||
impl From<walkdir::Error> for WalkError {
|
||||
fn from(e: walkdir::Error) -> WalkError {
|
||||
WalkError::from(&e)
|
||||
fn from(e: walkdir::Error) -> Self {
|
||||
Self::from(&e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&walkdir::Error> for WalkError {
|
||||
fn from(e: &walkdir::Error) -> WalkError {
|
||||
WalkError {
|
||||
fn from(e: &walkdir::Error) -> Self {
|
||||
Self {
|
||||
path: e.path().map(|p| p.to_owned()),
|
||||
depth: Some(e.depth()),
|
||||
raw: e.io_error().and_then(|e| e.raw_os_error()),
|
||||
@@ -182,15 +182,15 @@ impl From<&walkdir::Error> for WalkError {
|
||||
}
|
||||
|
||||
impl From<WalkError> for io::Error {
|
||||
fn from(e: WalkError) -> io::Error {
|
||||
io::Error::from(&e)
|
||||
fn from(e: WalkError) -> Self {
|
||||
Self::from(&e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&WalkError> for io::Error {
|
||||
fn from(e: &WalkError) -> io::Error {
|
||||
fn from(e: &WalkError) -> Self {
|
||||
e.raw
|
||||
.map(io::Error::from_raw_os_error)
|
||||
.map(Self::from_raw_os_error)
|
||||
.unwrap_or_else(|| ErrorKind::Other.into())
|
||||
}
|
||||
}
|
||||
@@ -221,7 +221,7 @@ impl WalkEntry {
|
||||
pub fn from_walkdir(
|
||||
result: walkdir::Result<DirEntry>,
|
||||
follow: Follow,
|
||||
) -> Result<WalkEntry, WalkError> {
|
||||
) -> Result<Self, WalkError> {
|
||||
let result = result.map_err(WalkError::from);
|
||||
|
||||
match result {
|
||||
@@ -242,7 +242,7 @@ impl WalkEntry {
|
||||
// Detect broken symlinks and replace them with explicit entries
|
||||
if let (Some(path), Some(depth)) = (e.path(), e.depth()) {
|
||||
if let Ok(meta) = path.symlink_metadata() {
|
||||
return Ok(WalkEntry {
|
||||
return Ok(Self {
|
||||
inner: Entry::Explicit(path.into(), depth),
|
||||
follow: Follow::Never,
|
||||
meta: Ok(meta).into(),
|
||||
@@ -278,7 +278,7 @@ impl WalkEntry {
|
||||
Entry::Explicit(path, _) => {
|
||||
// Path::file_name() only works if the last component is normal
|
||||
path.components()
|
||||
.last()
|
||||
.next_back()
|
||||
.map(|c| c.as_os_str())
|
||||
.unwrap_or_else(|| path.as_os_str())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::error::Error;
|
||||
use std::ffi::OsString;
|
||||
use std::io::{stderr, Write};
|
||||
@@ -97,6 +98,125 @@ impl Matcher for SingleExecMatcher {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MultiExecMatcher {
|
||||
executable: String,
|
||||
args: Vec<OsString>,
|
||||
exec_in_parent_dir: bool,
|
||||
/// Command to build while matching.
|
||||
command: RefCell<Option<argmax::Command>>,
|
||||
}
|
||||
|
||||
impl MultiExecMatcher {
|
||||
pub fn new(
|
||||
executable: &str,
|
||||
args: &[&str],
|
||||
exec_in_parent_dir: bool,
|
||||
) -> Result<Self, Box<dyn Error>> {
|
||||
let transformed_args = args.iter().map(OsString::from).collect();
|
||||
|
||||
Ok(Self {
|
||||
executable: executable.to_string(),
|
||||
args: transformed_args,
|
||||
exec_in_parent_dir,
|
||||
command: RefCell::new(None),
|
||||
})
|
||||
}
|
||||
|
||||
fn new_command(&self) -> argmax::Command {
|
||||
let mut command = argmax::Command::new(&self.executable);
|
||||
command.try_args(&self.args).unwrap();
|
||||
command
|
||||
}
|
||||
|
||||
fn run_command(&self, command: &mut argmax::Command, matcher_io: &mut MatcherIO) {
|
||||
match command.status() {
|
||||
Ok(status) => {
|
||||
if !status.success() {
|
||||
matcher_io.set_exit_code(1);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
writeln!(&mut stderr(), "Failed to run {}: {}", self.executable, e).unwrap();
|
||||
matcher_io.set_exit_code(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Matcher for MultiExecMatcher {
|
||||
fn matches(&self, file_info: &WalkEntry, matcher_io: &mut MatcherIO) -> bool {
|
||||
let path_to_file = if self.exec_in_parent_dir {
|
||||
if let Some(f) = file_info.path().file_name() {
|
||||
Path::new(".").join(f)
|
||||
} else {
|
||||
Path::new(".").join(file_info.path())
|
||||
}
|
||||
} else {
|
||||
file_info.path().to_path_buf()
|
||||
};
|
||||
let mut command = self.command.borrow_mut();
|
||||
let command = command.get_or_insert_with(|| self.new_command());
|
||||
|
||||
// Build command, or dispatch it before when it is long enough.
|
||||
if command.try_arg(&path_to_file).is_err() {
|
||||
if self.exec_in_parent_dir {
|
||||
match file_info.path().parent() {
|
||||
None => {
|
||||
// Root paths like "/" have no parent. Run them from the root to match GNU find.
|
||||
command.current_dir(file_info.path());
|
||||
}
|
||||
Some(parent) if parent == Path::new("") => {
|
||||
// Paths like "foo" have a parent of "". Avoid chdir("").
|
||||
}
|
||||
Some(parent) => {
|
||||
command.current_dir(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.run_command(command, matcher_io);
|
||||
|
||||
// Reset command status.
|
||||
*command = self.new_command();
|
||||
if let Err(e) = command.try_arg(&path_to_file) {
|
||||
writeln!(
|
||||
&mut stderr(),
|
||||
"Cannot fit a single argument {}: {}",
|
||||
&path_to_file.to_string_lossy(),
|
||||
e
|
||||
)
|
||||
.unwrap();
|
||||
matcher_io.set_exit_code(1);
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn finished_dir(&self, dir: &Path, matcher_io: &mut MatcherIO) {
|
||||
// Dispatch command for -execdir.
|
||||
if self.exec_in_parent_dir {
|
||||
let mut command = self.command.borrow_mut();
|
||||
if let Some(mut command) = command.take() {
|
||||
command.current_dir(Path::new(".").join(dir));
|
||||
self.run_command(&mut command, matcher_io);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn finished(&self, matcher_io: &mut MatcherIO) {
|
||||
// Dispatch command for -exec.
|
||||
if !self.exec_in_parent_dir {
|
||||
let mut command = self.command.borrow_mut();
|
||||
if let Some(mut command) = command.take() {
|
||||
self.run_command(&mut command, matcher_io);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn has_side_effects(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
/// No tests here, because we need to call out to an external executable. See
|
||||
/// `tests/exec_unit_tests.rs` instead.
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
use super::{Matcher, MatcherIO, WalkEntry};
|
||||
#[cfg(unix)]
|
||||
use uucore::error::UResult;
|
||||
|
||||
/// The latest mapping from dev_id to fs_type, used for saving mount info reads
|
||||
#[cfg(unix)]
|
||||
@@ -26,15 +28,12 @@ pub struct Cache {
|
||||
#[cfg(unix)]
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
error::Error,
|
||||
io::{stderr, Write},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn get_file_system_type(
|
||||
path: &Path,
|
||||
cache: &RefCell<Option<Cache>>,
|
||||
) -> Result<String, Box<dyn Error>> {
|
||||
pub fn get_file_system_type(path: &Path, cache: &RefCell<Option<Cache>>) -> UResult<String> {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
// use symlink_metadata (lstat under the hood) instead of metadata (stat) to make sure that it
|
||||
@@ -51,10 +50,7 @@ pub fn get_file_system_type(
|
||||
}
|
||||
}
|
||||
|
||||
let fs_list = match uucore::fsext::read_fs_list() {
|
||||
Ok(fs_list) => fs_list,
|
||||
Err(err) => Err(err)?,
|
||||
};
|
||||
let fs_list = uucore::fsext::read_fs_list()?;
|
||||
let result = fs_list
|
||||
.into_iter()
|
||||
.find(|fs| fs.dev_id == dev_id)
|
||||
|
||||
+31
-21
@@ -112,7 +112,7 @@ fn extract_bracket_expr(pattern: &str) -> Option<(String, &str)> {
|
||||
}
|
||||
|
||||
/// Converts a POSIX glob into a POSIX Basic Regular Expression
|
||||
fn glob_to_regex(pattern: &str) -> String {
|
||||
fn glob_to_regex(pattern: &str) -> Option<String> {
|
||||
let mut regex = String::new();
|
||||
|
||||
let mut chars = pattern.chars();
|
||||
@@ -130,9 +130,9 @@ fn glob_to_regex(pattern: &str) -> String {
|
||||
// If pattern ends with an unescaped <backslash>, fnmatch() shall return a
|
||||
// non-zero value (indicating either no match or an error).
|
||||
//
|
||||
// Most implementations return FNM_NOMATCH in this case, so return a regex that
|
||||
// Most implementations return FNM_NOMATCH in this case, so create a pattern that
|
||||
// never matches.
|
||||
return "$.".to_string();
|
||||
return None;
|
||||
}
|
||||
}
|
||||
'[' => {
|
||||
@@ -147,12 +147,12 @@ fn glob_to_regex(pattern: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
regex
|
||||
Some(regex)
|
||||
}
|
||||
|
||||
/// An fnmatch()-style glob matcher.
|
||||
pub struct Pattern {
|
||||
regex: Regex,
|
||||
regex: Option<Regex>,
|
||||
}
|
||||
|
||||
impl Pattern {
|
||||
@@ -165,13 +165,13 @@ impl Pattern {
|
||||
};
|
||||
|
||||
// As long as glob_to_regex() is correct, this should never fail
|
||||
let regex = parse_bre(&glob_to_regex(pattern), options).unwrap();
|
||||
let regex = glob_to_regex(pattern).map(|r| parse_bre(&r, options).unwrap());
|
||||
Self { regex }
|
||||
}
|
||||
|
||||
/// Test if this pattern matches a string.
|
||||
pub fn matches(&self, string: &str) -> bool {
|
||||
self.regex.is_match(string)
|
||||
self.regex.as_ref().is_some_and(|r| r.is_match(string))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,47 +179,52 @@ impl Pattern {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[track_caller]
|
||||
fn assert_glob_regex(glob: &str, regex: &str) {
|
||||
assert_eq!(glob_to_regex(glob).as_deref(), Some(regex));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literals() {
|
||||
assert_eq!(glob_to_regex(r"foo.bar"), r"foo\.bar");
|
||||
assert_glob_regex(r"foo.bar", r"foo\.bar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn regex_special() {
|
||||
assert_eq!(glob_to_regex(r"^foo.bar$"), r"\^foo\.bar\$");
|
||||
assert_glob_regex(r"^foo.bar$", r"\^foo\.bar\$");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wildcards() {
|
||||
assert_eq!(glob_to_regex(r"foo?bar*baz"), r"foo.bar.*baz");
|
||||
assert_glob_regex(r"foo?bar*baz", r"foo.bar.*baz");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escapes() {
|
||||
assert_eq!(glob_to_regex(r"fo\o\?bar\*baz\\"), r"foo?bar\*baz\\");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete_escape() {
|
||||
assert_eq!(glob_to_regex(r"foo\"), r"$.");
|
||||
assert_glob_regex(r"fo\o\?bar\*baz\\", r"foo?bar\*baz\\");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_brackets() {
|
||||
assert_eq!(glob_to_regex(r"foo[bar][!baz]"), r"foo[bar][^baz]");
|
||||
assert_glob_regex(r"foo[bar][!baz]", r"foo[bar][^baz]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complex_brackets() {
|
||||
assert_eq!(
|
||||
glob_to_regex(r"[!]!.*[\[.].][=]=][:space:]-]"),
|
||||
r"[^]!.*[\[.].][=]=][:space:]-]"
|
||||
assert_glob_regex(
|
||||
r"[!]!.*[\[.].][=]=][:space:]-]",
|
||||
r"[^]!.*[\[.].][=]=][:space:]-]",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_brackets() {
|
||||
assert_eq!(glob_to_regex(r"foo[bar[!baz"), r"foo\[bar\[!baz");
|
||||
assert_glob_regex(r"foo[bar[!baz", r"foo\[bar\[!baz");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete_escape() {
|
||||
assert_eq!(glob_to_regex(r"foo\"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -235,4 +240,9 @@ mod tests {
|
||||
|
||||
assert!(!Pattern::new(r"foo*BAR", true).matches("BAR--foo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete_escape_matches() {
|
||||
assert!(!Pattern::new(r"foo\", false).matches("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
+21
-49
@@ -3,7 +3,7 @@
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
use super::{Matcher, MatcherIO, WalkEntry};
|
||||
use super::{ComparableValue, Matcher, MatcherIO, WalkEntry};
|
||||
|
||||
#[cfg(unix)]
|
||||
use nix::unistd::Group;
|
||||
@@ -11,63 +11,39 @@ use nix::unistd::Group;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
pub struct GroupMatcher {
|
||||
gid: Option<u32>,
|
||||
gid: ComparableValue,
|
||||
}
|
||||
|
||||
impl GroupMatcher {
|
||||
#[cfg(unix)]
|
||||
pub fn from_group_name(group: &str) -> GroupMatcher {
|
||||
pub fn from_group_name(group: &str) -> Option<Self> {
|
||||
// get gid from group name
|
||||
let Ok(group) = Group::from_name(group) else {
|
||||
return GroupMatcher { gid: None };
|
||||
};
|
||||
|
||||
let Some(group) = group else {
|
||||
// This if branch is to determine whether a certain group exists in the system.
|
||||
// If a certain group does not exist in the system,
|
||||
// the result will need to be returned according to
|
||||
// the flag bit of whether to invert the result.
|
||||
return GroupMatcher { gid: None };
|
||||
};
|
||||
|
||||
GroupMatcher {
|
||||
gid: Some(group.gid.as_raw()),
|
||||
}
|
||||
let group = Group::from_name(group).ok()??;
|
||||
let gid = group.gid.as_raw();
|
||||
Some(Self::from_gid(gid))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn from_gid(gid: u32) -> GroupMatcher {
|
||||
GroupMatcher { gid: Some(gid) }
|
||||
pub fn from_gid(gid: u32) -> Self {
|
||||
Self::from_comparable(ComparableValue::EqualTo(gid as u64))
|
||||
}
|
||||
|
||||
pub fn from_comparable(gid: ComparableValue) -> Self {
|
||||
Self { gid }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn from_group_name(_group: &str) -> GroupMatcher {
|
||||
GroupMatcher { gid: None }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn from_gid(_gid: u32) -> GroupMatcher {
|
||||
GroupMatcher { gid: None }
|
||||
}
|
||||
|
||||
pub fn gid(&self) -> &Option<u32> {
|
||||
&self.gid
|
||||
pub fn from_group_name(_group: &str) -> Option<Self> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Matcher for GroupMatcher {
|
||||
#[cfg(unix)]
|
||||
fn matches(&self, file_info: &WalkEntry, _: &mut MatcherIO) -> bool {
|
||||
let Ok(metadata) = file_info.metadata() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let file_gid = metadata.gid();
|
||||
|
||||
// When matching the -group parameter in find/matcher/mod.rs,
|
||||
// it has been judged that the group does not exist and an error is returned.
|
||||
// So use unwarp() directly here.
|
||||
self.gid.unwrap() == file_gid
|
||||
match file_info.metadata() {
|
||||
Ok(metadata) => self.gid.matches(metadata.gid().into()),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
@@ -136,7 +112,8 @@ mod tests {
|
||||
.unwrap()
|
||||
.name;
|
||||
|
||||
let matcher = super::GroupMatcher::from_group_name(file_group.as_str());
|
||||
let matcher =
|
||||
super::GroupMatcher::from_group_name(file_group.as_str()).expect("group should exist");
|
||||
assert!(
|
||||
matcher.matches(&file_info, &mut matcher_io),
|
||||
"group should match"
|
||||
@@ -146,18 +123,13 @@ mod tests {
|
||||
let time_string = Local::now().format("%Y%m%d%H%M%S").to_string();
|
||||
let matcher = GroupMatcher::from_group_name(time_string.as_str());
|
||||
assert!(
|
||||
matcher.gid().is_none(),
|
||||
matcher.is_none(),
|
||||
"group name {} should not exist",
|
||||
time_string
|
||||
);
|
||||
|
||||
// Testing group id
|
||||
let matcher = GroupMatcher::from_gid(file_gid);
|
||||
assert!(
|
||||
matcher.gid().is_some(),
|
||||
"group id {} should exist",
|
||||
file_gid
|
||||
);
|
||||
assert!(
|
||||
matcher.matches(&file_info, &mut matcher_io),
|
||||
"group id should match"
|
||||
|
||||
@@ -38,7 +38,7 @@ pub struct LinkNameMatcher {
|
||||
}
|
||||
|
||||
impl LinkNameMatcher {
|
||||
pub fn new(pattern_string: &str, caseless: bool) -> LinkNameMatcher {
|
||||
pub fn new(pattern_string: &str, caseless: bool) -> Self {
|
||||
let pattern = Pattern::new(pattern_string, caseless);
|
||||
Self { pattern }
|
||||
}
|
||||
|
||||
@@ -51,15 +51,15 @@ impl Matcher for AndMatcher {
|
||||
.any(super::Matcher::has_side_effects)
|
||||
}
|
||||
|
||||
fn finished_dir(&self, dir: &Path) {
|
||||
fn finished_dir(&self, dir: &Path, matcher_io: &mut MatcherIO) {
|
||||
for m in &self.submatchers {
|
||||
m.finished_dir(dir);
|
||||
m.finished_dir(dir, matcher_io);
|
||||
}
|
||||
}
|
||||
|
||||
fn finished(&self) {
|
||||
fn finished(&self, matcher_io: &mut MatcherIO) {
|
||||
for m in &self.submatchers {
|
||||
m.finished();
|
||||
m.finished(matcher_io);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,15 +127,15 @@ impl Matcher for OrMatcher {
|
||||
.any(super::Matcher::has_side_effects)
|
||||
}
|
||||
|
||||
fn finished_dir(&self, dir: &Path) {
|
||||
fn finished_dir(&self, dir: &Path, matcher_io: &mut MatcherIO) {
|
||||
for m in &self.submatchers {
|
||||
m.finished_dir(dir);
|
||||
m.finished_dir(dir, matcher_io);
|
||||
}
|
||||
}
|
||||
|
||||
fn finished(&self) {
|
||||
fn finished(&self, matcher_io: &mut MatcherIO) {
|
||||
for m in &self.submatchers {
|
||||
m.finished();
|
||||
m.finished(matcher_io);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,15 +222,15 @@ impl Matcher for ListMatcher {
|
||||
.any(super::Matcher::has_side_effects)
|
||||
}
|
||||
|
||||
fn finished_dir(&self, dir: &Path) {
|
||||
fn finished_dir(&self, dir: &Path, matcher_io: &mut MatcherIO) {
|
||||
for m in &self.submatchers {
|
||||
m.finished_dir(dir);
|
||||
m.finished_dir(dir, matcher_io);
|
||||
}
|
||||
}
|
||||
|
||||
fn finished(&self) {
|
||||
fn finished(&self, matcher_io: &mut MatcherIO) {
|
||||
for m in &self.submatchers {
|
||||
m.finished();
|
||||
m.finished(matcher_io);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,17 +346,16 @@ impl Matcher for NotMatcher {
|
||||
self.submatcher.has_side_effects()
|
||||
}
|
||||
|
||||
fn finished_dir(&self, dir: &Path) {
|
||||
self.submatcher.finished_dir(dir);
|
||||
fn finished_dir(&self, dir: &Path, matcher_io: &mut MatcherIO) {
|
||||
self.submatcher.finished_dir(dir, matcher_io);
|
||||
}
|
||||
|
||||
fn finished(&self) {
|
||||
self.submatcher.finished();
|
||||
fn finished(&self, matcher_io: &mut MatcherIO) {
|
||||
self.submatcher.finished(matcher_io);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::find::matchers::quit::QuitMatcher;
|
||||
|
||||
+18
-5
@@ -119,7 +119,13 @@ impl Ls {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn print(&self, file_info: &WalkEntry, mut out: impl Write, print_error_message: bool) {
|
||||
fn print(
|
||||
&self,
|
||||
file_info: &WalkEntry,
|
||||
matcher_io: &mut MatcherIO,
|
||||
mut out: impl Write,
|
||||
print_error_message: bool,
|
||||
) {
|
||||
use nix::unistd::{Gid, Group, Uid, User};
|
||||
use std::os::unix::fs::{MetadataExt, PermissionsExt};
|
||||
|
||||
@@ -183,14 +189,20 @@ impl Ls {
|
||||
e
|
||||
)
|
||||
.unwrap();
|
||||
uucore::error::set_exit_code(1);
|
||||
matcher_io.set_exit_code(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn print(&self, file_info: &WalkEntry, mut out: impl Write, print_error_message: bool) {
|
||||
fn print(
|
||||
&self,
|
||||
file_info: &WalkEntry,
|
||||
matcher_io: &mut MatcherIO,
|
||||
mut out: impl Write,
|
||||
print_error_message: bool,
|
||||
) {
|
||||
use std::os::windows::fs::MetadataExt;
|
||||
|
||||
let metadata = file_info.metadata().unwrap();
|
||||
@@ -246,7 +258,7 @@ impl Ls {
|
||||
e
|
||||
)
|
||||
.unwrap();
|
||||
uucore::error::set_exit_code(1);
|
||||
matcher_io.set_exit_code(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,10 +268,11 @@ impl Ls {
|
||||
impl Matcher for Ls {
|
||||
fn matches(&self, file_info: &WalkEntry, matcher_io: &mut MatcherIO) -> bool {
|
||||
if let Some(file) = &self.output_file {
|
||||
self.print(file_info, file, true);
|
||||
self.print(file_info, matcher_io, file, true);
|
||||
} else {
|
||||
self.print(
|
||||
file_info,
|
||||
matcher_io,
|
||||
&mut *matcher_io.deps.get_output().borrow_mut(),
|
||||
false,
|
||||
);
|
||||
|
||||
+229
-89
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,15 @@ impl NameMatcher {
|
||||
impl Matcher for NameMatcher {
|
||||
fn matches(&self, file_info: &WalkEntry, _: &mut MatcherIO) -> bool {
|
||||
let name = file_info.file_name().to_string_lossy();
|
||||
|
||||
#[cfg(unix)]
|
||||
if name.len() > 1 && name.chars().all(|x| x == '/') {
|
||||
self.pattern.matches("/")
|
||||
} else {
|
||||
self.pattern.matches(&name)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
self.pattern.matches(&name)
|
||||
}
|
||||
}
|
||||
@@ -32,7 +41,6 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::find::matchers::tests::get_dir_entry_for;
|
||||
use crate::find::tests::FakeDependencies;
|
||||
|
||||
use std::io::ErrorKind;
|
||||
|
||||
#[cfg(unix)]
|
||||
@@ -126,4 +134,22 @@ mod tests {
|
||||
let deps = FakeDependencies::new();
|
||||
assert!(matcher.matches(&link_f, &mut deps.new_matcher_io()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn slash_match_returns_true() {
|
||||
let dir_to_match = get_dir_entry_for("///", "");
|
||||
let matcher = NameMatcher::new("/", true);
|
||||
let deps = FakeDependencies::new();
|
||||
assert!(matcher.matches(&dir_to_match, &mut deps.new_matcher_io()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn only_one_slash() {
|
||||
let dir_to_match = get_dir_entry_for("/", "");
|
||||
let matcher = NameMatcher::new("/", false);
|
||||
let deps = FakeDependencies::new();
|
||||
assert!(matcher.matches(&dir_to_match, &mut deps.new_matcher_io()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ pub enum ComparisonType {
|
||||
impl ComparisonType {
|
||||
fn mode_bits_match(self, pattern: u32, value: u32) -> bool {
|
||||
match self {
|
||||
ComparisonType::Exact => (0o7777 & value) == pattern,
|
||||
ComparisonType::AtLeast => (value & pattern) == pattern,
|
||||
ComparisonType::AnyOf => pattern == 0 || (value & pattern) > 0,
|
||||
Self::Exact => (0o7777 & value) == pattern,
|
||||
Self::AtLeast => (value & pattern) == pattern,
|
||||
Self::AnyOf => pattern == 0 || (value & pattern) > 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ pub enum PrintDelimiter {
|
||||
impl std::fmt::Display for PrintDelimiter {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
PrintDelimiter::Newline => writeln!(f),
|
||||
PrintDelimiter::Null => write!(f, "\0"),
|
||||
Self::Newline => writeln!(f),
|
||||
Self::Null => write!(f, "\0"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,13 @@ impl Printer {
|
||||
}
|
||||
}
|
||||
|
||||
fn print(&self, file_info: &WalkEntry, mut out: impl Write, print_error_message: bool) {
|
||||
fn print(
|
||||
&self,
|
||||
file_info: &WalkEntry,
|
||||
matcher_io: &mut MatcherIO,
|
||||
mut out: impl Write,
|
||||
print_error_message: bool,
|
||||
) {
|
||||
match write!(
|
||||
out,
|
||||
"{}{}",
|
||||
@@ -54,7 +60,7 @@ impl Printer {
|
||||
e
|
||||
)
|
||||
.unwrap();
|
||||
uucore::error::set_exit_code(1);
|
||||
matcher_io.set_exit_code(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,10 +71,11 @@ impl Printer {
|
||||
impl Matcher for Printer {
|
||||
fn matches(&self, file_info: &WalkEntry, matcher_io: &mut MatcherIO) -> bool {
|
||||
if let Some(file) = &self.output_file {
|
||||
self.print(file_info, file, true);
|
||||
self.print(file_info, matcher_io, file, true);
|
||||
} else {
|
||||
self.print(
|
||||
file_info,
|
||||
matcher_io,
|
||||
&mut *matcher_io.deps.get_output().borrow_mut(),
|
||||
false,
|
||||
);
|
||||
@@ -124,11 +131,6 @@ mod tests {
|
||||
let deps = FakeDependencies::new();
|
||||
|
||||
assert!(matcher.matches(&abbbc, &mut deps.new_matcher_io()));
|
||||
|
||||
// Reset the exit code global variable in case we run another test after this one
|
||||
// See https://github.com/uutils/coreutils/issues/5777
|
||||
uucore::error::set_exit_code(0);
|
||||
|
||||
assert!(deps.get_output_as_string().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user