| 1 | package repair |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "io" |
| 6 | "path/filepath" |
| 7 | ) |
| 8 | |
| 9 | // Read through a regular-file handle that permits atomic replacement on |
| 10 | // Windows. Pending-update readers run before acquiring the mutation lock; |
| 11 | // their handles must not prevent another owner from archiving the marker. |
| 12 | func readRepairRegularFile(path string) ([]byte, error) { |
| 13 | file, err := openRepairRegularRead(path) |
| 14 | if err != nil { |
| 15 | return nil, err |
| 16 | } |
| 17 | defer file.Close() |
| 18 | info, err := file.Stat() |
| 19 | if err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | if !info.Mode().IsRegular() { |
| 23 | return nil, fmt.Errorf("%s is not a regular file", filepath.Base(path)) |
| 24 | } |
| 25 | return io.ReadAll(file) |
| 26 | } |
| 27 |