@@ -2,7 +2,6 @@ package trcshfs
22
33import (
44 "bytes"
5- "errors"
65 "fmt"
76 "io"
87 "os"
@@ -31,22 +30,24 @@ func NewTrcshMemFs() *TrcshMemFs {
3130
3231func (t * TrcshMemFs ) WriteToMemFile (coreConfig * coreconfig.CoreConfig , byteData * []byte , path string ) {
3332 t .MemCacheLock .Lock ()
34- if _ , err := (* t .BillyFs ).Stat (path ); errors .Is (err , os .ErrNotExist ) {
35- if strings .HasPrefix (path , "./" ) {
36- path = strings .TrimLeft (path , "./" )
37- }
38- memFile , err := t .Create (path )
39- if err != nil {
40- coreConfig .Log .Printf ("Error creating memfile %s: %v" , path , err )
41- }
42- memFile .Write (* byteData )
43- memFile .Close ()
44- t .MemCacheLock .Unlock ()
45- coreConfig .Log .Printf ("Wrote memfile: %s" , path )
46- } else {
33+ if strings .HasPrefix (path , "./" ) {
34+ path = strings .TrimLeft (path , "./" )
35+ }
36+ // Remove the file if it exists, ignoring errors if it doesn't
37+ t .Remove (path )
38+ memFile , err := t .Create (path )
39+ if err != nil {
40+ coreConfig .Log .Printf ("Error creating memfile %s: %v" , path , err )
4741 t .MemCacheLock .Unlock ()
48- coreConfig .Log .Printf ("Memfile already exists: %s" , path )
42+ return
43+ }
44+ _ , writeErr := memFile .Write (* byteData )
45+ if writeErr != nil {
46+ coreConfig .Log .Printf ("Error writing to memfile %s: %v" , path , writeErr )
4947 }
48+ memFile .Close ()
49+ t .MemCacheLock .Unlock ()
50+ coreConfig .Log .Printf ("Wrote memfile: %s" , path )
5051}
5152
5253func (t * TrcshMemFs ) ReadDir (path string ) ([]os.FileInfo , error ) {
0 commit comments