Skip to content

Commit a7518f5

Browse files
committed
MIGRATION-434
1 parent 2ec6c4d commit a7518f5

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
test.out
2+
outputs/
3+
*.log
4+
.DS_Store
5+

fscopy/fscopy.go

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"bufio"
1919
"bytes"
2020
"fmt"
21-
"io"
21+
//"io"
2222
"os"
2323
"os/exec"
2424
"strings"
@@ -35,7 +35,7 @@ type RemoteCred struct {
3535
func (rc *RemoteCred) Get() error {
3636
reader := bufio.NewReader(os.Stdin)
3737
fmt.Println(
38-
"Enter PasswordLess ssh User for remote copy. Leave Blank for cluster without remote nodes): ",
38+
"Enter ssh User for remote copy. Leave Blank for cluster without remote nodes): ",
3939
)
4040
username, err := reader.ReadString('\n')
4141
if err != nil {
@@ -96,7 +96,7 @@ func (fcjwp *FSCopyJobWithPattern) StartCopyRemoteWithPattern() error {
9696
// we invoke bash shell because the wildcards are interpretted by bash shell not the rsync program
9797
fcjwp.Dcrlog.Debug(
9898
fmt.Sprintf(
99-
"preparing command rsync -az --include=%s --exclude=%s --info=progress2 %s@%s:%s/ %s",
99+
"preparing command rsync -az --include=%s --exclude=%s --progress %s@%s:%s/ %s",
100100
filepattern,
101101
excludepattern,
102102
fcjwp.CopyJobDetails.Src.Username,
@@ -110,7 +110,7 @@ func (fcjwp *FSCopyJobWithPattern) StartCopyRemoteWithPattern() error {
110110
"bash",
111111
"-c",
112112
fmt.Sprintf(
113-
"rsync -az --include=%s --exclude=%s --info=progress2 %s@%s:%s/ %s",
113+
"rsync -az --include=%s --exclude=%s --progress %s@%s:%s/ %s",
114114
filepattern,
115115
excludepattern,
116116
fcjwp.CopyJobDetails.Src.Username,
@@ -119,9 +119,28 @@ func (fcjwp *FSCopyJobWithPattern) StartCopyRemoteWithPattern() error {
119119
fcjwp.CopyJobDetails.Dst.Path,
120120
))
121121

122-
cmd.Stdout = fcjwp.CopyJobDetails.Output
123-
124-
stderr, err := cmd.StderrPipe()
122+
//commenting out the cmd.Stdout because it is being used to capture the output below.
123+
//cmd.Stdout = fcjwp.CopyJobDetails.Output
124+
125+
//Allow user to provide input if needed.
126+
cmd.Stdin = os.Stdin
127+
cmd.Stdout = os.Stdout
128+
cmd.Stderr = os.Stderr
129+
130+
//Executing the rsync command
131+
fcjwp.Dcrlog.Debug("rsync command start")
132+
fmt.Println("Please add your password for SSH connection:")
133+
err := cmd.Run()
134+
if err != nil {
135+
fcjwp.Dcrlog.Debug(
136+
fmt.Sprintf("StartCopyRemoteWithPattern: error doing remote copy job wait %w", err),
137+
)
138+
return fmt.Errorf("StartCopyRemoteWithPattern: error doing remote copy job wait %w", err)
139+
}
140+
return nil
141+
142+
// Removing stderr pipe for now. cmd.StderrPipe() The error produced by the command will appear in real time in the terminal.
143+
/* stderr, err := cmd.StderrPipe()
125144
if err != nil {
126145
return err
127146
}
@@ -149,6 +168,7 @@ func (fcjwp *FSCopyJobWithPattern) StartCopyRemoteWithPattern() error {
149168
return fmt.Errorf("StartCopyRemoteWithPattern: error doing remote copy job wait %w", err)
150169
}
151170
return nil
171+
*/
152172
}
153173

154174
// Copy job
@@ -169,7 +189,7 @@ type FSCopyJob struct {
169189
func (fcj *FSCopyJob) StartCopyRemote() error {
170190
// var cmd *exec.Cmd
171191

172-
fcj.Dcrlog.Debug(fmt.Sprintf("preparing command rsync -az --info=progress2 %s@%s:%s/ %s",
192+
fcj.Dcrlog.Debug(fmt.Sprintf("preparing command rsync -az --progress %s@%s:%s/ %s",
173193
fcj.Src.Username,
174194
fcj.Src.Hostname,
175195
fcj.Src.Path,
@@ -178,7 +198,7 @@ func (fcj *FSCopyJob) StartCopyRemote() error {
178198
cmd := exec.Command(
179199
"rsync",
180200
"-az",
181-
"--info=progress2",
201+
"--progress",
182202
fmt.Sprintf(`%s@%s:%s`,
183203
fcj.Src.Username,
184204
fcj.Src.Hostname,
@@ -187,9 +207,24 @@ func (fcj *FSCopyJob) StartCopyRemote() error {
187207
fcj.Dst.Path),
188208
)
189209

190-
cmd.Stdout = fcj.Output
210+
//cmd.Stdout = fcj.Output
211+
// Allow user to provide input if needed
212+
cmd.Stdin = os.Stdin
213+
cmd.Stdout = os.Stdout
214+
cmd.Stderr = os.Stderr
215+
191216

192-
stderr, err := cmd.StderrPipe()
217+
fcj.Dcrlog.Debug("starting rsync command")
218+
// Ask for SSH password
219+
fmt.Println("Please add your password for SSH connection ")
220+
err := cmd.Run()
221+
if err != nil {
222+
fcj.Dcrlog.Debug(fmt.Sprintf("error doing remote copy job wait %w", err))
223+
return fmt.Errorf("error doing remote copy job wait %w", err)
224+
}
225+
return nil
226+
227+
/* stderr, err := cmd.StderrPipe()
193228
if err != nil {
194229
return err
195230
}
@@ -214,6 +249,8 @@ func (fcj *FSCopyJob) StartCopyRemote() error {
214249
}
215250
216251
return nil
252+
*/
253+
217254
}
218255

219256
func (fcj *FSCopyJob) StartCopyLocal() error {

0 commit comments

Comments
 (0)