diff options
author | Runxi Yu <me@runxiyu.org> | 2025-01-04 22:04:06 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-01-04 22:04:06 +0800 |
commit | ca92770b428709f3c8f577ea81b8944802394b85 (patch) | |
tree | ac497a4e2d820d3b5d5f3b23a2f9d42dce2e09a4 /config.go | |
parent | Use Open_file_at instead of Open (diff) | |
download | maild-ca92770b428709f3c8f577ea81b8944802394b85.tar.gz maild-ca92770b428709f3c8f577ea81b8944802394b85.tar.zst maild-ca92770b428709f3c8f577ea81b8944802394b85.zip |
Clean up directory file descriptors
Diffstat (limited to '')
-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() + } +} |