File tree 4 files changed +23
-14
lines changed
4 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ Versioning].
16
16
17
17
- Correct typo in the ` ghasum help verify ` output.
18
18
- Enable cache eviction on ` ghasum init ` .
19
+ - Ensure ` ghasum verify ` outcome is linked to ` gha.sum ` content.
19
20
20
21
## [ v0.4.0] - 2025-04-27
21
22
Original file line number Diff line number Diff line change @@ -33,8 +33,8 @@ If the checksum file does not exist the process shall exit immediately with an
33
33
error.
34
34
35
35
If the checksum file exists the process shall obtain a lock on it, if this is
36
- not possible to process shall exit immediately (it means the file may be edited
37
- by another process leading to an inconsistent state) .
36
+ not possible the process shall exit immediately. Otherwise the file could be
37
+ changed by another process potentially leading to an inconsistent sumfile .
38
38
39
39
If the file lock is obtained, the process shall first read it and parse it
40
40
completely to extract the sumfile version. If this fails the process shall exit
@@ -62,6 +62,11 @@ This process does not verify any of the checksums currently in the sumfile.
62
62
If the checksum file does not exist the process shall exit immediately with an
63
63
error.
64
64
65
+ If the checksum file exists the process shall obtain a lock on it, if this is
66
+ not possible the process shall exit immediately. Otherwise the file could be
67
+ changed during the verification process resulting in a potential mismatch
68
+ between verification outcome and sumfile content.
69
+
65
70
If the checksum file exists the process shall read and parse it fully. If this
66
71
fails the process shall exit immediately. Else it shall recompute the checksums
67
72
(see [ Computing Checksums] ) for all actions in the target (see [ Collecting
Original file line number Diff line number Diff line change @@ -203,17 +203,6 @@ func open(base string) (*os.File, error) {
203
203
return file , nil
204
204
}
205
205
206
- func read (repo fs.FS ) ([]byte , error ) {
207
- raw , err := fs .ReadFile (repo , ghasumPath )
208
- if errors .Is (err , fs .ErrNotExist ) {
209
- return nil , ErrNotInitialized
210
- } else if err != nil {
211
- return nil , errors .Join (ErrSumfileRead , err )
212
- }
213
-
214
- return raw , nil
215
- }
216
-
217
206
func remove (base string ) error {
218
207
fullGhasumPath := path .Join (base , ghasumPath )
219
208
if err := os .Remove (fullGhasumPath ); err != nil {
Original file line number Diff line number Diff line change @@ -187,11 +187,21 @@ func Update(cfg *Config, force bool) error {
187
187
// Verification report checksums that do not match and checksums that are
188
188
// missing. It does not report checksums that are not used.
189
189
func Verify (cfg * Config ) ([]Problem , error ) {
190
- raw , err := read (cfg .Repo )
190
+ file , err := open (cfg .Path )
191
191
if err != nil {
192
192
return nil , err
193
193
}
194
194
195
+ defer func () {
196
+ _ = unlock (cfg .Path )
197
+ _ = file .Close ()
198
+ }()
199
+
200
+ raw , err := io .ReadAll (file )
201
+ if err != nil {
202
+ return nil , errors .Join (ErrSumfileRead , err )
203
+ }
204
+
195
205
stored , err := decode (raw )
196
206
if err != nil {
197
207
return nil , err
@@ -208,5 +218,9 @@ func Verify(cfg *Config) ([]Problem, error) {
208
218
}
209
219
210
220
result := compare (fresh , stored )
221
+ if err := unlock (cfg .Path ); err != nil {
222
+ return nil , err
223
+ }
224
+
211
225
return result , nil
212
226
}
You can’t perform that action at this time.
0 commit comments