use the open state file for refresh when possible
Only open a new file descriptor for RefreshState if we haven't written a state, and don't have the correct state open already. This prevents windows from failing to refresh a locked state.
This commit is contained in:
parent
8fb8b2cffc
commit
a84b4a669a
|
@ -119,8 +119,20 @@ func (s *LocalState) RefreshState() error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
if s.PathOut == "" {
|
||||||
|
s.PathOut = s.Path
|
||||||
|
}
|
||||||
|
|
||||||
var reader io.Reader
|
var reader io.Reader
|
||||||
if !s.written {
|
|
||||||
|
// The s.Path file is only OK to read if we have not written any state out
|
||||||
|
// (in which case the same state needs to be read in), and no state output file
|
||||||
|
// has been opened (possibly via a lock) or the input path is different
|
||||||
|
// than the output path.
|
||||||
|
// This is important for Windows, as if the input file is the same as the
|
||||||
|
// output file, and the output file has been locked already, we can't open
|
||||||
|
// the file again.
|
||||||
|
if !s.written && (s.stateFileOut == nil || s.Path != s.PathOut) {
|
||||||
// we haven't written a state file yet, so load from Path
|
// we haven't written a state file yet, so load from Path
|
||||||
f, err := os.Open(s.Path)
|
f, err := os.Open(s.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue