Skip to content

Bugfix/snapshot diff - #120

Merged
markusressel merged 2 commits into
mainfrom
bugfix/snapshot-diff
May 28, 2026
Merged

Bugfix/snapshot diff#120
markusressel merged 2 commits into
mainfrom
bugfix/snapshot-diff

Conversation

@markusressel

@markusressel markusressel commented May 28, 2026

Copy link
Copy Markdown
Owner

This pull request refactors and improves file existence and diff state logic in the ZFS snapshot codebase, making the code more modular and testable. It introduces a new utility function for file existence checks, renames key methods for clarity, and adds comprehensive unit tests for diff state determination.

Refactoring and logic improvements:

  • Replaced direct file existence checks in SnapshotFile.Exists() with a new utility function util.FileExists, and updated all usages to call this new function for consistency and testability. (internal/data/file_browser_entry.go, internal/util/file.go) [1] [2]
  • Renamed CheckIfFileHasChanged to IsRealFileDifferent in the Snapshot struct, clarifying its purpose, and updated all references accordingly. (internal/zfs/snapshot.go, internal/data/file_browser_entry.go) [1] [2]
  • Refactored DetermineDiffState to use the new file existence checks and to handle all combinations of real and snapshot file presence, improving correctness and maintainability. (internal/zfs/snapshot.go)

Testing:

  • Added a comprehensive table-driven unit test for DetermineDiffState, covering all key scenarios: added, equal, modified, deleted, and neither file exists. (internal/zfs/snapshot_test.go)

Utility function:

  • Introduced util.FileExists(path string) bool for consistent and reusable file existence checks throughout the codebase. (internal/util/file.go)

… deleted/neither cases

- Refactor TestDetermineDiffState to use a table-driven approach for clarity and maintainability
- Add test cases for deleted files and files missing from both real and snapshot
- Extract file setup logic into a helper function for reuse
- Simplify DetermineDiffState logic for correctness and readability
@markusressel markusressel self-assigned this May 28, 2026
@markusressel markusressel added the bug Something isn't working label May 28, 2026
@markusressel
markusressel merged commit 41ebcd5 into main May 28, 2026
3 checks passed
@markusressel
markusressel deleted the bugfix/snapshot-diff branch May 28, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant