Commit 7fe98cc
committed
calcHash: Remove checking file size
Let calcHash() unconditionally hash whatever buffer it is asked to hash,
and let its callers explicitly check if the buffer is too large before
calling calcHash(). This makes things simpler and less error-prone
(no extra source of truth about whether the file is too large, we don't
need to remember to check if calcHash() fails, we can be sure calcHash()
will actually update the provided hash), and actually faster (since just
calculating the buffer size, i.e. adding line lengths, is faster than
md5 calculation).
In particular, this fixes the following bugs:
1. Since ReOpen() doesn't check calcHash() return value, if the reloaded
file is too large while the old version of the file is not,
calcHash() returns ErrFileTooLarge and doesn't update origHash, so
so Modified() returns true since the reloaded file's md5 sum doesn't
match the old origHash, so micro wrongly reports the newly reloaded
file as modified.
2. Since Modified() doesn't check calcHash() return value, Modified()
may return false positives or false negatives if the buffer has
*just* become too large so calcHash() returns ErrFileTooLarge and
doesn't update `buff`.1 parent 93efc9e commit 7fe98cc
2 files changed
+11
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 67 | | |
72 | 68 | | |
73 | 69 | | |
| |||
649 | 645 | | |
650 | 646 | | |
651 | 647 | | |
652 | | - | |
| 648 | + | |
653 | 649 | | |
654 | 650 | | |
655 | | - | |
656 | 651 | | |
657 | | - | |
658 | | - | |
| 652 | + | |
659 | 653 | | |
660 | 654 | | |
661 | 655 | | |
662 | | - | |
| 656 | + | |
663 | 657 | | |
664 | | - | |
| 658 | + | |
665 | 659 | | |
666 | | - | |
667 | | - | |
668 | | - | |
| 660 | + | |
669 | 661 | | |
670 | 662 | | |
671 | 663 | | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | 664 | | |
677 | | - | |
678 | 665 | | |
679 | 666 | | |
680 | 667 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 15 | + | |
| 16 | + | |
20 | 17 | | |
21 | | - | |
22 | | - | |
23 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
| |||
0 commit comments