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 is the file name of the main back up file.
|
||||||
fileName string
|
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
|
// 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.
|
// packed multi-chan backup, and the rename to the main back up file.
|
||||||
tempFileName string
|
tempFileName string
|
||||||
@ -132,32 +129,15 @@ func (b *MultiFile) UpdateAndSwap(newBackup PackedMulti) error {
|
|||||||
func (b *MultiFile) ExtractMulti(keyChain keychain.KeyRing) (*Multi, error) {
|
func (b *MultiFile) ExtractMulti(keyChain keychain.KeyRing) (*Multi, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// If the backup file isn't already set, then we'll attempt to open it
|
// We'll return an error if the main file isn't currently set.
|
||||||
// anew.
|
if b.fileName == "" {
|
||||||
if b.mainFile == nil {
|
return nil, ErrNoBackupFileExists
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before we start to read the file, we'll ensure that the next read
|
// Now that we've confirmed the target file is populated, we'll read
|
||||||
// call will start from the front of the file.
|
// all the contents of the file. This function ensures that file is
|
||||||
_, err = b.mainFile.Seek(0, 0)
|
// always closed, even if we can't read the contents.
|
||||||
if err != nil {
|
multiBytes, err := ioutil.ReadFile(b.fileName)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user