MCPcopy
hub / github.com/mattermost/mattermost / updateManifestAndCSSFiles

Function updateManifestAndCSSFiles

server/channels/utils/subpath.go:141–168  ·  view source on GitHub ↗
(staticDir, pathToReplace, newPath, subpath string)

Source from the content-addressed store, hash-verified

139}
140
141func updateManifestAndCSSFiles(staticDir, pathToReplace, newPath, subpath string) error {
142 if pathToReplace == newPath {
143 mlog.Debug("No need to rewrite unmodified manifest.json and *.css files", mlog.String("from_subpath", pathToReplace), mlog.String("to_subpath", newPath))
144 return nil
145 }
146
147 mlog.Debug("Rewriting manifest.json and *.css files", mlog.String("from_subpath", pathToReplace), mlog.String("to_subpath", newPath))
148 // Rewrite the manifest.json and *.css references to `/static/*` (or a previously rewritten subpath).
149 err := filepath.Walk(staticDir, func(walkPath string, info os.FileInfo, err error) error {
150 if filepath.Base(walkPath) == "manifest.json" || filepath.Ext(walkPath) == ".css" {
151 old, err := os.ReadFile(walkPath)
152 if err != nil {
153 return errors.Wrapf(err, "failed to open %s", walkPath)
154 }
155 n := strings.Replace(string(old), pathToReplace, newPath, -1)
156 if err = os.WriteFile(walkPath, []byte(n), 0); err != nil {
157 return errors.Wrapf(err, "failed to update %s with subpath %s", walkPath, subpath)
158 }
159 }
160
161 return nil
162 })
163 if err != nil {
164 return errors.Wrapf(err, "error walking %s", staticDir)
165 }
166
167 return nil
168}
169
170// UpdateAssetsSubpath rewrites assets in the /client directory to assume the application is hosted
171// at the given subpath instead of at the root. No changes are written unless necessary.

Callers 1

UpdateAssetsSubpathInDirFunction · 0.85

Calls 4

DebugMethod · 0.65
StringMethod · 0.65
ReadFileMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…