close tempfiles, fix path print

This commit is contained in:
scottf
2021-04-22 12:47:21 -04:00
parent 96546040a3
commit 486df98373
3 changed files with 18 additions and 2 deletions

View File

@@ -235,6 +235,7 @@ func newFileStoreWithCreated(fcfg FileStoreConfig, cfg StreamConfig, created tim
if err != nil {
return nil, fmt.Errorf("storage directory is not writable")
}
tmpfile.Close()
os.Remove(tmpfile.Name())
fs := &fileStore{
@@ -3192,7 +3193,12 @@ func (mb *msgBlock) close(sync bool) {
if sync {
syncAndClose(mb.mfd, mb.ifd)
} else {
go syncAndClose(mb.mfd, mb.ifd)
if mb.mfd != nil {
mb.mfd.Close()
}
if mb.ifd != nil {
mb.ifd.Close()
}
}
mb.mfd = nil
mb.ifd = nil
@@ -3209,6 +3215,14 @@ func (fs *fileStore) Delete() error {
return ErrStoreClosed
}
fs.Purge()
pdir := path.Join(fs.fcfg.StoreDir, purgeDir)
// If purge directory still exists then we need to wait
// in place and remove since rename would fail.
if _, err := os.Stat(pdir); err == nil {
os.RemoveAll(pdir)
}
if err := fs.Stop(); err != nil {
return err
}

View File

@@ -180,6 +180,7 @@ func (s *Server) enableJetStream(cfg JetStreamConfig) error {
if err != nil {
return fmt.Errorf("storage directory is not writable")
}
tmpfile.Close()
os.Remove(tmpfile.Name())
}
@@ -199,7 +200,7 @@ func (s *Server) enableJetStream(cfg JetStreamConfig) error {
s.Noticef("---------------- JETSTREAM ----------------")
s.Noticef(" Max Memory: %s", friendlyBytes(cfg.MaxMemory))
s.Noticef(" Max Storage: %s", friendlyBytes(cfg.MaxStore))
s.Noticef(" Store Directory: %q", cfg.StoreDir)
s.Noticef(" Store Directory: \"%s\"", cfg.StoreDir)
s.Noticef("-------------------------------------------")
// Setup our internal subscriptions.

View File

@@ -309,6 +309,7 @@ func (s *Server) bootstrapRaftNode(cfg *RaftConfig, knownPeers []string, allPeer
if err != nil {
return fmt.Errorf("raft: storage directory is not writable")
}
tmpfile.Close()
os.Remove(tmpfile.Name())
return writePeerState(cfg.Store, &peerState{knownPeers, expected})