@@ -3,6 +3,7 @@ package lock
33import  (
44	"context" 
55	"fmt" 
6+ 	"os" 
67	"os/exec" 
78	"strings" 
89	"time" 
@@ -11,17 +12,25 @@ import (
1112// Run acquires a lock under the specified key, executes the command, and then unlocks the key. 
1213// Returns ErrLocked if the key is already locked. Otherwise returns combined stdout and stderr 
1314// of the command and the command error. If the unlock step fails the lock expires after 24 hours. 
14- func  (c  * Client ) Run (ctx  context.Context , key , command  string ) ( string ,  error )  {
15+ func  (c  * Client ) Run (ctx  context.Context , key , command  string ) error  {
1516	// use context.Background here so that unlock runs even if the context is cancelled 
1617	defer  c .Unlock (context .Background (), key ) //nolint:errcheck 
1718
1819	err  :=  c .Lock (ctx , key , time .Hour * 24 ) //nolint:gomnd 
1920	if  err  !=  nil  {
20- 		return  "" ,  fmt .Errorf ("lock failed: %w" , err )
21+ 		return  fmt .Errorf ("lock failed: %w" , err )
2122	}
2223
24+ 	// Build command 
2325	fields  :=  strings .Fields (command )
24- 	cmdout ,  cmderr   :=  exec .CommandContext (ctx , fields [0 ], fields [1 :]... ). CombinedOutput ( ) //nolint:gosec 
26+ 	cmd   :=  exec .CommandContext (ctx , fields [0 ], fields [1 :]... ) //nolint:gosec 
2527
26- 	return  strings .TrimSpace (string (cmdout )), cmderr 
28+ 	// Write to std outputs 
29+ 	cmd .Stdout  =  os .Stdout 
30+ 	cmd .Stderr  =  os .Stderr 
31+ 
32+ 	if  err  :=  cmd .Run (); err  !=  nil  {
33+ 		return  fmt .Errorf ("command failed: %w" , err )
34+ 	}
35+ 	return  nil 
2736}
0 commit comments