Copyright | (c) Fuzz Leonard 2025 |
---|---|
License | MIT |
Maintainer | cyborg@bionicfuzz.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Clod.FileSystem.Checksums
Description
This module provides functions for tracking file changes using checksums. It calculates XXH3 (64-bit) hashes of file content and maintains a database of files that have been processed, allowing us to detect new, modified, deleted, and renamed files.
The file checksum database is stored as a Dhall configuration file with the following structure:
{ files = { "pathtofile1.txt" = { path = "pathtofile1.txt" , checksum = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , lastModified = "2025-01-01T12:00:00Z" , optimizedName = "path-to-file1.txt" } , "pathtofile2.md" = { path = "pathtofile2.md" , checksum = "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730" , lastModified = "2025-01-02T14:30:00Z" , optimizedName = "path-to-file2.md" } } , checksums = { "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" = "pathtofile1.txt" , "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730" = "pathtofile2.md" } , lastStagingDir = Some ".staging20250101-120000" , lastRunTime = "2025-01-01T12:00:00Z" }
This database allows efficient lookup of files by path or checksum, detection of renamed files (same content with different paths), and tracking of previous staging directories.
Synopsis
- calculateChecksum :: ByteString -> Checksum
- checksumFile :: FileReadCap -> FilePath -> ClodM Checksum
- initializeDatabase :: ClodM ClodDatabase
- loadDatabase :: FilePath -> ClodM ClodDatabase
- saveDatabase :: FilePath -> ClodDatabase -> ClodM ()
- updateDatabase :: ClodDatabase -> FilePath -> Checksum -> UTCTime -> OptimizedName -> ClodDatabase
- detectFileChanges :: FileReadCap -> ClodDatabase -> [FilePath] -> FilePath -> ClodM ([(FilePath, FileStatus)], [(FilePath, FilePath)])
- findChangedFiles :: ClodDatabase -> [(FilePath, Checksum, UTCTime)] -> ClodM [(FilePath, FileStatus)]
- findRenamedFiles :: ClodDatabase -> [(FilePath, FileStatus)] -> [(FilePath, FilePath)]
- getFileStatus :: ClodDatabase -> FilePath -> Checksum -> ClodM FileStatus
- data FileStatus
- cleanupStagingDirectories :: ClodM ()
- flushMissingEntries :: FileReadCap -> ClodDatabase -> FilePath -> ClodM ClodDatabase
Checksum operations
calculateChecksum :: ByteString -> Checksum Source #
Calculate XXH3 checksum (64-bit) of a ByteString XXH3 is a fast non-cryptographic hash function with excellent performance
checksumFile :: FileReadCap -> FilePath -> ClodM Checksum Source #
Calculate the checksum of a file Only text files are allowed to be checksummed
Database operations
initializeDatabase :: ClodM ClodDatabase Source #
Initialize a new, empty database
loadDatabase :: FilePath -> ClodM ClodDatabase Source #
Load the database from disk using Dhall
saveDatabase :: FilePath -> ClodDatabase -> ClodM () Source #
Save the database to disk using Dhall serialization
updateDatabase :: ClodDatabase -> FilePath -> Checksum -> UTCTime -> OptimizedName -> ClodDatabase Source #
Update the database with a new file entry
Change detection
detectFileChanges :: FileReadCap -> ClodDatabase -> [FilePath] -> FilePath -> ClodM ([(FilePath, FileStatus)], [(FilePath, FilePath)]) Source #
Detect changes by comparing current files with database
findChangedFiles :: ClodDatabase -> [(FilePath, Checksum, UTCTime)] -> ClodM [(FilePath, FileStatus)] Source #
Find files that need processing (new, modified, renamed)
findRenamedFiles :: ClodDatabase -> [(FilePath, FileStatus)] -> [(FilePath, FilePath)] Source #
Find files that have been renamed
getFileStatus :: ClodDatabase -> FilePath -> Checksum -> ClodM FileStatus Source #
Detect file status by comparing against database
data FileStatus Source #
Data type for tracking file status
Constructors
Unchanged | File has not changed |
New | New file |
Modified | Existing file with modified content |
Deleted | File no longer exists |
Renamed FilePath | File was renamed (new path) |
Instances
Database management
cleanupStagingDirectories :: ClodM () Source #
Clean up old staging directories
flushMissingEntries :: FileReadCap -> ClodDatabase -> FilePath -> ClodM ClodDatabase Source #
Find and remove missing files from the database