Skip to content

Commit f0ff827

Browse files
committed
[#76509] linux-client: Prevent half-initialized FileStore on I/O errors
Signed-off-by: Łukasz Kędziora <lkedziora@antmicro.com>
1 parent 9676902 commit f0ff827

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

devices/linux-client/actions/file_store.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ func (q *FileStore) removeFile(idx int) error {
125125
}
126126

127127
func (q *FileStore) Reload() error {
128-
q.itemsByIdx = nil
129-
130128
itemsByIdx := make(map[int]FileBlob)
131-
132129
files, err := ioutil.ReadDir(q.itemsPath())
133130
if err != nil {
134131
return err
@@ -169,6 +166,11 @@ func (q *FileStore) Reload() error {
169166
}
170167
}
171168

169+
// After everything was loaded from the filesystem, we can populate the FileStore.
170+
// At this point, no errors can happen so we can update the entire object atomically.
171+
q.itemsLock.Lock()
172+
defer q.itemsLock.Unlock()
173+
172174
if minIdx == -1 {
173175
q.writeIdx = 0
174176
q.readIdx = 0

0 commit comments

Comments
 (0)