mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
Merge pull request #4456 from Roasbeef/windows-scb-close
chanbackup: always close SCB file after reading
This commit is contained in:
commit
aa8539501f
@ -39,9 +39,6 @@ type MultiFile struct {
|
||||
// fileName is the file name of the main back up file.
|
||||
fileName string
|
||||
|
||||
// mainFile is an open handle to the main back up file.
|
||||
mainFile *os.File
|
||||
|
||||
// tempFileName is the name of the file that we'll use to stage a new
|
||||
// packed multi-chan backup, and the rename to the main back up file.
|
||||
tempFileName string
|
||||
@ -132,32 +129,15 @@ func (b *MultiFile) UpdateAndSwap(newBackup PackedMulti) error {
|
||||
func (b *MultiFile) ExtractMulti(keyChain keychain.KeyRing) (*Multi, error) {
|
||||
var err error
|
||||
|
||||
// If the backup file isn't already set, then we'll attempt to open it
|
||||
// anew.
|
||||
if b.mainFile == nil {
|
||||
// We'll return an error if the main file isn't currently set.
|
||||
if b.fileName == "" {
|
||||
return nil, ErrNoBackupFileExists
|
||||
}
|
||||
|
||||
// Otherwise, we'll open the file to prep for reading the
|
||||
// contents.
|
||||
b.mainFile, err = os.Open(b.fileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// We'll return an error if the main file isn't currently set.
|
||||
if b.fileName == "" {
|
||||
return nil, ErrNoBackupFileExists
|
||||
}
|
||||
|
||||
// Before we start to read the file, we'll ensure that the next read
|
||||
// call will start from the front of the file.
|
||||
_, err = b.mainFile.Seek(0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// With our seek successful, we'll now attempt to read the contents of
|
||||
// the entire file in one swoop.
|
||||
multiBytes, err := ioutil.ReadAll(b.mainFile)
|
||||
// Now that we've confirmed the target file is populated, we'll read
|
||||
// all the contents of the file. This function ensures that file is
|
||||
// always closed, even if we can't read the contents.
|
||||
multiBytes, err := ioutil.ReadFile(b.fileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user