MCPcopy Index your code
hub / github.com/cli/cli / readFrom

Function readFrom

internal/skills/lockfile/lockfile.go:53–75  ·  view source on GitHub ↗

readFrom loads the lock file from an open file handle. Returns an empty file if the content is empty, corrupt, or incompatible.

(f *os.File)

Source from the content-addressed store, hash-verified

51// readFrom loads the lock file from an open file handle.
52// Returns an empty file if the content is empty, corrupt, or incompatible.
53func readFrom(f *os.File) (*file, error) {
54 if _, err := f.Seek(0, 0); err != nil {
55 return nil, fmt.Errorf("could not seek lock file: %w", err)
56 }
57 data, err := io.ReadAll(f)
58 if err != nil {
59 return nil, fmt.Errorf("could not read lock file: %w", err)
60 }
61 if len(data) == 0 {
62 return newFile(), nil
63 }
64
65 var lf file
66 if err := json.Unmarshal(data, &lf); err != nil {
67 return newFile(), nil //nolint:nilerr // graceful: corrupt file means fresh state
68 }
69
70 if lf.Version != lockVersion || lf.Skills == nil {
71 return newFile(), nil
72 }
73
74 return &lf, nil
75}
76
77// writeTo persists the lock file through an open file handle.
78func writeTo(f *os.File, lf *file) error {

Callers 1

RecordInstallFunction · 0.85

Calls 2

newFileFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected