Read returns the contents of the file for the given URI. If no file exists at the path or the URI is of an invalid type, an error is returned.
(ctx context.Context, u uri.URI, create bool)
| 121 | // If no file exists at the path or the URI is of an invalid type, an error is |
| 122 | // returned. |
| 123 | func (m *Manager) tryReading(ctx context.Context, u uri.URI, create bool) (doc Document, err error) { |
| 124 | m.mu.Lock() |
| 125 | defer func() { |
| 126 | if err == nil { |
| 127 | // Always return a copy of the document |
| 128 | doc = doc.Copy() |
| 129 | } |
| 130 | m.mu.Unlock() |
| 131 | }() |
| 132 | |
| 133 | // TODO(siegs): check staleness for files read from disk? |
| 134 | var found bool |
| 135 | if doc, found = m.docs[u]; !found { |
| 136 | _, err = m.readAndParse(ctx, u) |
| 137 | doc = m.docs[u] |
| 138 | if !create { |
| 139 | delete(m.docs, u) |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | if os.IsNotExist(err) { |
| 144 | err = os.ErrNotExist |
| 145 | } |
| 146 | |
| 147 | return doc, err |
| 148 | } |
| 149 | |
| 150 | // Queue enqueues the given function as something that should be run in |
| 151 | // the near future. The URI will be used as a key so if another function |
no test coverage detected