Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#26: Prevent file footguns #29

Merged
merged 65 commits into from
Aug 30, 2021
Merged

#26: Prevent file footguns #29

merged 65 commits into from
Aug 30, 2021

Conversation

Shadow53
Copy link
Owner

@Shadow53 Shadow53 commented Aug 27, 2021

Resolves #26 and #28.

Implements two checks:

Check 1: Last Paths

This check validates that the paths being used in the current operation are the same as the most recent operation on that hoard. If the paths are different, this may constitute an unintentional environment change. Users can double-check that the paths being used are the intended ones, and then use the --force flag to make the operation go through.

Check 2: Remote Operations

This check uses (hopefully synchronized) records from other systems to determine if the most recent update of a file happened locally or on a remote system. If it happened on a remote system, any backup operation is cancelled to prevent accidentally overwriting remote changes. Again, this check can be disabled using the --force flag.

This commit includes the relevant `LastPaths` types, implementing checks
for changed paths. Also includes a `--force` flag for allowing the
operation to continue without the check.
Rather than creating a sum of scores, which can easily have collisions
between different sets of scores, keep track of every score in the tree
path.

A path is considered a better match using the following algorithm:

1. The path with more nodes is better.
2. If paths are equal length, the one with more higher numbers is
   better.
   - Of `A: [7, 3, 2, 1]` and `B: [5, 4, 3, 2]`, `B` is the better match
     because it generally has higher scores than `A`.
3. If the paths have equal numbers of higher scores, abort with error.
@codecov
Copy link

codecov bot commented Aug 27, 2021

Codecov Report

Merging #29 (3e2d486) into main (decffb7) will decrease coverage by 4.00%.
The diff coverage is 41.99%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #29      +/-   ##
==========================================
- Coverage   60.84%   56.83%   -4.01%     
==========================================
  Files          16       17       +1     
  Lines        1637     1990     +353     
  Branches      395      509     +114     
==========================================
+ Hits          996     1131     +135     
- Misses        355      517     +162     
- Partials      286      342      +56     
Impacted Files Coverage Δ
src/config/builder/environment/exe.rs 70.83% <0.00%> (ø)
src/config/hoard.rs 1.65% <0.00%> (-0.09%) ⬇️
src/config/mod.rs 21.29% <0.00%> (-8.99%) ⬇️
src/lib.rs 100.00% <ø> (ø)
src/env_vars.rs 50.00% <6.25%> (-12.50%) ⬇️
src/config/builder/mod.rs 60.35% <19.04%> (-2.72%) ⬇️
src/checkers/history/last_paths.rs 47.03% <47.03%> (ø)
src/config/builder/hoard.rs 62.03% <50.00%> (+0.83%) ⬆️
src/config/builder/envtrie.rs 61.14% <67.32%> (-0.36%) ⬇️
src/combinator.rs 82.70% <100.00%> (+1.34%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update decffb7...3e2d486. Read the comment docs.

src/checkers/history/mod.rs Outdated Show resolved Hide resolved
src/checkers/history/operation.rs Outdated Show resolved Hide resolved
src/checkers/history/operation.rs Show resolved Hide resolved
src/config/builder/envtrie.rs Outdated Show resolved Hide resolved
src/config/hoard.rs Outdated Show resolved Hide resolved
src/config/mod.rs Outdated Show resolved Hide resolved
src/config/mod.rs Outdated Show resolved Hide resolved
src/config/mod.rs Outdated Show resolved Hide resolved
@Shadow53 Shadow53 linked an issue Aug 30, 2021 that may be closed by this pull request
@Shadow53
Copy link
Owner Author

Tests pass, codecov does not consider the Python script for coverage (which provides more coverage than unit tests could, imo), and I am content with the state of the codebase at this point.

@Shadow53 Shadow53 merged commit 6b441df into main Aug 30, 2021
@Shadow53 Shadow53 deleted the 26-prevent-file-footguns branch September 22, 2021 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Process paths only when environments match Track file modifications to prevent footguns
1 participant