MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / AttachFileSystem

Method AttachFileSystem

internal/plugins/plugins.go:345–388  ·  view source on GitHub ↗

Adds an embedded file system to the plugin

(f embed.FS)

Source from the content-addressed store, hash-verified

343
344// Adds an embedded file system to the plugin
345func (p *Plugin) AttachFileSystem(f embed.FS) error {
346
347 p.files.fileSystem = f
348
349 p.files.filePaths = make(map[string]string)
350
351 // Walk the directory tree rooted at "datafiles"
352 err := fs.WalkDir(p.files.fileSystem, `.`, func(path string, d fs.DirEntry, err error) error {
353 if err != nil {
354 return err // propagate the error
355 }
356
357 // If it's not a directory, add the path to the list
358 if d.IsDir() {
359 return nil
360 }
361
362 // Handle datafiles folder.
363 dfPos := strings.Index(path, dataFilesFolder)
364 if dfPos != -1 {
365 // map the short path to long embedded path
366 p.files.filePaths[path[dfPos+len(dataFilesFolder):]] = path
367 return nil
368 }
369
370 // Handle data-overlays folder.
371 // This is a special folder that overlays data onto other data
372 dfPos = strings.Index(path, dataOverlaysFilesFolder)
373 if dfPos != -1 {
374 // map the short path to long embedded path
375 // Put data-overlays/ prefix on for purposes of filefinding later.
376 p.files.filePaths[dataOverlaysFilesFolder+path[dfPos+len(dataOverlaysFilesFolder):]] = path
377 return nil
378 }
379
380 return nil
381 })
382
383 if err != nil {
384 return fmt.Errorf("plug.AddFiles() for %s: %w", p.name, err)
385 }
386
387 return nil
388}
389
390func (p *Plugin) WriteBytes(identifier string, bytes []byte) error {
391

Callers 15

newTestPluginFunction · 0.95
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80
initFunction · 0.80

Calls

no outgoing calls

Tested by 1

newTestPluginFunction · 0.76