msgstore_fs: rename log dir when network is renamed
This commit is contained in:
parent
b1d89163f8
commit
2ce97bcc12
@ -553,6 +553,16 @@ func (ms *fsMessageStore) ListTargets(network *network, start, end time.Time, li
|
||||
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 {
|
||||
year, month, day := t.Date()
|
||||
return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
|
||||
|
9
user.go
9
user.go
@ -854,6 +854,15 @@ func (u *user) updateNetwork(record *Network) (*network, error) {
|
||||
// otherwise they'll get closed
|
||||
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
|
||||
u.addNetwork(updatedNetwork)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user