Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bandetto committed Jun 24, 2024
1 parent 442837f commit ae9f3e2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions helper/restore_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (r *RestoreReader) endPluginProcess() {
// Reap plugin process and log plugin stderr. This should be called on every
// reader that used a plugin as to not leave any zombies behind.
func finalizeReaderPlugin(r *RestoreReader) {
if r != nil && r.pluginCmd != nil && !r.pluginCmd.isEnded {
if r != nil && r.pluginCmd != nil && !r.pluginCmd.isFinalized {
r.logPluginStderr()
r.endPluginProcess()
// Only finalize once per plugin command.
r.pluginCmd.isEnded = true
r.pluginCmd.isFinalized = true
}
}

Expand Down Expand Up @@ -175,6 +175,7 @@ func doRestoreAgent() error {

filename := replaceContentInFilename(*dataFile, contentToRestore)
readers[contentToRestore], err = getRestoreDataReader(filename, segmentTOC[contentToRestore], oidList)

if err != nil {
logError(fmt.Sprintf("Error encountered getting restore data reader for single data file: %v", err))
return err
Expand Down Expand Up @@ -354,8 +355,9 @@ func doRestoreAgent() error {
}
log(fmt.Sprintf("Oid %d: Copied %d bytes into the pipe", oid, bytesRead))

// SDF reads the pipe by chunks in several iterations but Wait()
// call will close the pipe immediately. Let defer do the work.
// SDF reads the pipe output by chunks in several iterations, but
// Wait() from finalizeReaderPlugin() call will close the pipe
// immediately. Let defer close it instead.
if !*singleDataFile {
finalizeReaderPlugin(readers[contentToRestore])
}
Expand Down Expand Up @@ -538,11 +540,11 @@ func getSubsetFlag(fileToRead string, pluginConfig *utils.PluginConfig) bool {
}

// pluginCmd is needed to keep track of readable stderr and whether the command
// has already been ended.
// has already been finalized.
type pluginCmd struct {
*exec.Cmd
stderrBuffer *bytes.Buffer
isEnded bool
isFinalized bool
}

func newPluginCmd(errBuf *bytes.Buffer, name string, arg ...string) *pluginCmd {
Expand Down

0 comments on commit ae9f3e2

Please sign in to comment.