Browse Source

Add missing locks

Matt Bolt 1 year ago
parent
commit
73e0ffbc6d
1 changed files with 9 additions and 0 deletions
  1. 9 0
      core/pkg/storage/memorystorage.go

+ 9 - 0
core/pkg/storage/memorystorage.go

@@ -37,6 +37,9 @@ func (ms *MemoryStorage) FullPath(path string) string {
 
 // Stat returns the StorageStats for the specific path.
 func (ms *MemoryStorage) Stat(path string) (*StorageInfo, error) {
+	ms.lock.Lock()
+	defer ms.lock.Unlock()
+
 	path = filepath.Clean(path)
 	if file, ok := ms.directPaths[path]; ok {
 		return &StorageInfo{
@@ -52,6 +55,9 @@ func (ms *MemoryStorage) Stat(path string) (*StorageInfo, error) {
 // Read uses the relative path of the storage combined with the provided path to
 // read the contents.
 func (ms *MemoryStorage) Read(path string) ([]byte, error) {
+	ms.lock.Lock()
+	defer ms.lock.Unlock()
+
 	path = filepath.Clean(path)
 
 	if file, ok := ms.directPaths[path]; ok {
@@ -64,6 +70,9 @@ func (ms *MemoryStorage) Read(path string) ([]byte, error) {
 // Write uses the relative path of the storage combined with the provided path
 // to write a new file or overwrite an existing file.
 func (ms *MemoryStorage) Write(path string, data []byte) error {
+	ms.lock.Lock()
+	defer ms.lock.Unlock()
+
 	paths, pFile := memfile.Split(path)
 
 	f := memfile.NewMemoryFile(pFile, data)