diff options
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -3,6 +3,7 @@ package main import ( "bufio" "os" + "reflect" "sync" "go.lindenii.runxiyu.org/lindenii-common/misc" @@ -50,3 +51,19 @@ func prepare_dirs() error { } return nil } + +// clean_up_dirs closes all directories. It should only be called before +// program exit. +func clean_up_dirs() { + directories_mutex.Lock() + defer directories_mutex.Unlock() + directories_rv := reflect.ValueOf(directories) + directories_rt := directories_rv.Type() + for i := range directories_rt.NumField() { + dir, ok := directories_rv.Field(i).Interface().(misc.Dir_t) + if !ok { + panic("directories contains a field that's not misc.Dir_t") + } + dir.Close() + } +} |