Skip to content

MikeMirzayanov/rhsum

Repository files navigation

rhsum

rhsum (Rheo Sum) is a single-file C++ utility for deterministic polynomial hashing of a file or directory tree treated as one continuous virtual byte stream.

The canonical build command for this project is:

g++ -O3 -std=c++20 -march=native -pthread rhsum.cpp -o rhsum

Layout

.
├── .github/workflows/ci.yml
├── .gitignore
├── Makefile
├── README.md
├── install.ps1
├── install.sh
├── rhsum.cpp
├── scripts/build.py
├── scripts/run_tests.py
├── tests/test_constant_1mb_42.py
├── tests/test_directory_tree.py
├── tests/test_follow_symlink_cycle.py
├── tests/test_follow_symlink_name.py
├── tests/test_follow_symlinks.py
├── tests/test_invalid_cli_args.py
├── tests/test_invalid_threads_arg.py
├── tests/test_permission_denied.py
├── tests/test_single_symlink_input.py
├── tests/test_special_name_only.py
├── tests/testlib.py
├── uninstall.ps1
└── uninstall.sh

Requirements

  • C++20-capable environment
  • g++ with C++20 support
  • pthread for the canonical Unix build

Linux and other POSIX platforms use an mmap fast path for file reads. Other platforms fall back to standard C++ file I/O.

Build

Canonical:

g++ -O3 -std=c++20 -march=native -pthread rhsum.cpp -o rhsum

Convenience wrapper:

make

Cross-platform build wrapper:

python3 scripts/build.py

Install into your user PATH:

make install

Install directly from GitHub with curl | bash:

curl -fsSL https://raw.githubusercontent.com/MikeMirzayanov/rhsum/main/install.sh | sudo bash

User-only install from the same script:

curl -fsSL https://raw.githubusercontent.com/MikeMirzayanov/rhsum/main/install.sh | bash -s -- --user

Remove the Unix installation:

curl -fsSL https://raw.githubusercontent.com/MikeMirzayanov/rhsum/main/uninstall.sh | sudo bash

User-only Unix uninstall:

curl -fsSL https://raw.githubusercontent.com/MikeMirzayanov/rhsum/main/uninstall.sh | bash -s -- --user

Windows PowerShell install:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/MikeMirzayanov/rhsum/main/install.ps1))) -User

Windows system-wide install from an elevated PowerShell:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/MikeMirzayanov/rhsum/main/install.ps1))) -System

Windows PowerShell uninstall:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/MikeMirzayanov/rhsum/main/uninstall.ps1))) -User

Windows system-wide uninstall from an elevated PowerShell:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/MikeMirzayanov/rhsum/main/uninstall.ps1))) -System

Install system-wide for all users:

sudo make install-system

Run tests:

make test

Run only the Valgrind pass:

make test-valgrind

Cross-platform test runner:

python3 scripts/run_tests.py

Valgrind pass on Linux:

python3 scripts/run_tests.py --valgrind

Usage

./rhsum [options] <file|dir>

Options

  • -T, --threads <N>: number of worker threads
  • -L, --follow-symlinks: follow symbolic links
  • -v: print execution statistics to stderr
  • --help: show usage help

Examples

./rhsum rhsum.cpp
./rhsum .
./rhsum -T 8 -v .

Notes

  • Input paths are sorted lexicographically before composition to keep output deterministic.
  • If the input is a single file, rhsum hashes only the file bytes.
  • If the input is a directory, rhsum always traverses it recursively and hashes relative paths from the traversal root for both files and directories, plus file contents.
  • Filesystem entities that are neither regular files nor directories contribute only their relative names and type markers, not any payload bytes.
  • Empty directories therefore affect the resulting hash.
  • Symlink and FIFO tests auto-skip on platforms where those primitives are unavailable or restricted.
  • make test also runs the suite under Valgrind when Valgrind is available; this catches many memory errors and leaks in covered paths, but it is not a formal proof that no memory bugs exist.
  • For a 1 MiB file filled with byte value 42, the direct-file hash is d97a894407600000.
  • The repository currently has no license file. Add one before publishing if reuse by others is intended.

make install copies rhsum to ~/.local/bin by default and appends that directory to ~/.profile and ~/.bashrc if needed. It affects new shell sessions; the current shell still needs export PATH="$HOME/.local/bin:$PATH" or a restart.

make install-system installs rhsum into /usr/local/bin and writes /etc/profile.d/rhsum-path.sh. This usually requires root and affects new login shells for all users.

About

rhsum (Rheo Sum) is a single-file C++ utility for deterministic polynomial hashing of a file or directory tree treated as one continuous virtual byte stream

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors