Skip to content

Commit c773f03

Browse files
committed
support switching back to regexp path configuration
1 parent 3f240f8 commit c773f03

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

internal/core/path_manager.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919
func pathConfCanBeUpdated(oldPathConf *conf.Path, newPathConf *conf.Path) bool {
2020
clone := oldPathConf.Clone()
2121

22+
clone.Name = newPathConf.Name
23+
clone.Regexp = newPathConf.Regexp
24+
2225
clone.Record = newPathConf.Record
2326

2427
clone.RPICameraBrightness = newPathConf.RPICameraBrightness
@@ -38,11 +41,6 @@ func pathConfCanBeUpdated(oldPathConf *conf.Path, newPathConf *conf.Path) bool {
3841
clone.RPICameraIDRPeriod = newPathConf.RPICameraIDRPeriod
3942
clone.RPICameraBitrate = newPathConf.RPICameraBitrate
4043

41-
if oldPathConf.Name == "all" || oldPathConf.Name == "all_others" {
42-
clone.Name = newPathConf.Name
43-
clone.Regexp = newPathConf.Regexp
44-
}
45-
4644
return newPathConf.Equal(clone)
4745
}
4846

@@ -221,15 +219,16 @@ func (pm *pathManager) doReloadConf(newPaths map[string]*conf.Path) {
221219
continue
222220
}
223221

224-
// path now belongs to a different config with exact name match
225-
if newConf, exists := newPaths[pathName]; exists && newConf.Name == pathName {
226-
if pathConfCanBeUpdated(path.conf, newConf) {
227-
// Hot reload the path with the new configuration
228-
go path.reloadConf(newConf)
229-
} else {
230-
// Configuration cannot be hot reloaded: recreate the path
231-
pm.removeAndClosePath(path)
222+
// path now belongs to a different config
223+
if pathConf.Name != path.conf.Name {
224+
// path config can be hot reloaded
225+
if pathConfCanBeUpdated(path.conf, pathConf) {
226+
go path.reloadConf(pathConf)
227+
continue
232228
}
229+
230+
// Configuration cannot be hot reloaded: delete the path
231+
pm.removeAndClosePath(path)
233232
continue
234233
}
235234

internal/core/path_manager_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,17 @@ func TestPathConfigurationHotReload(t *testing.T) {
169169

170170
// Verify the path is still ready and functional
171171
require.Equal(t, true, pathData.Ready)
172+
173+
// revert configuration
174+
httpRequest(t, hc, http.MethodDelete, "http://localhost:9997/v3/config/paths/delete/undefined_stream",
175+
nil, nil)
176+
177+
// Give the system time to process the configuration change
178+
time.Sleep(200 * time.Millisecond)
179+
180+
// Verify the path now uses the old configuration
181+
pathData, err = p.pathManager.APIPathsGet("undefined_stream")
182+
require.NoError(t, err)
183+
require.Equal(t, "undefined_stream", pathData.Name)
184+
require.Equal(t, "all", pathData.ConfName)
172185
}

0 commit comments

Comments
 (0)