msgstore_fs: rename log dir when network is renamed

This commit is contained in:
Simon Ser 2021-10-15 18:11:04 +02:00
parent b1d89163f8
commit 2ce97bcc12
2 changed files with 19 additions and 0 deletions

View File

@ -553,6 +553,16 @@ func (ms *fsMessageStore) ListTargets(network *network, start, end time.Time, li
return targets, nil return targets, nil
} }
func (ms *fsMessageStore) RenameNetwork(oldNet, newNet *network) error {
oldDir := filepath.Join(ms.root, escapeFilename(oldNet.GetName()))
newDir := filepath.Join(ms.root, escapeFilename(newNet.GetName()))
// Avoid loosing data by overwriting an existing directory
if _, err := os.Stat(newDir); err == nil {
return fmt.Errorf("destination %q already exists", newDir)
}
return os.Rename(oldDir, newDir)
}
func truncateDay(t time.Time) time.Time { func truncateDay(t time.Time) time.Time {
year, month, day := t.Date() year, month, day := t.Date()
return time.Date(year, month, day, 0, 0, 0, 0, t.Location()) return time.Date(year, month, day, 0, 0, 0, 0, t.Location())

View File

@ -854,6 +854,15 @@ func (u *user) updateNetwork(record *Network) (*network, error) {
// otherwise they'll get closed // otherwise they'll get closed
u.removeNetwork(network) u.removeNetwork(network)
// The filesystem message store needs to be notified whenever the network
// is renamed
fsMsgStore, isFS := u.msgStore.(*fsMessageStore)
if isFS && updatedNetwork.GetName() != network.GetName() {
if err := fsMsgStore.RenameNetwork(network, updatedNetwork); err != nil {
network.logger.Printf("failed to update FS message store network name to %q: %v", updatedNetwork.GetName(), err)
}
}
// This will re-connect to the upstream server // This will re-connect to the upstream server
u.addNetwork(updatedNetwork) u.addNetwork(updatedNetwork)