feat: add WithContext functions for all subprocess-related code

Also deprecate the existing subprocess calls.
This commit is contained in:
Jose Diaz-Gonzalez
2024-02-11 23:04:20 -05:00
parent 03df28af87
commit bcf25ba5cd
5 changed files with 177 additions and 22 deletions

View File

@@ -33,12 +33,17 @@ type SftpCopyInput struct {
// CallSftpCopy copies a file to a remote host via sftp
func CallSftpCopy(input SftpCopyInput) (SftpCopyResult, error) {
return CallSftpCopyWithContext(context.Background(), input)
}
// CallSftpCopyWithContext copies a file to a remote host via sftp with the given context
func CallSftpCopyWithContext(ctx context.Context, input SftpCopyInput) (SftpCopyResult, error) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGQUIT,
syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(ctx)
go func() {
<-signals
cancel()