1
0

qemu: add CopyDirectory (via scp)

This commit is contained in:
dump_stack() 2023-02-15 11:20:30 +00:00
parent 668bc1e391
commit d59049e531
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC

View File

@ -352,16 +352,25 @@ func (q System) AsyncCommand(user, cmd string) (err error) {
"nohup sh -c '%s' > /dev/null 2> /dev/null < /dev/null &", cmd))
}
// CopyFile is copy file from local machine to remote through ssh/scp
func (q *System) CopyFile(user, localPath, remotePath string) (err error) {
func (q System) scp(user, localPath, remotePath string, recursive bool) (err error) {
addrPort := strings.Split(q.sshAddrPort, ":")
addr := addrPort[0]
port := addrPort[1]
cmd := exec.Command("scp", "-P", port,
args := []string{
"-P", port,
"-o", "StrictHostKeyChecking=no",
"-o", "LogLevel=error",
localPath, user+"@"+addr+":"+remotePath)
}
if recursive {
args = append(args, "-r")
}
args = append(args, localPath, user+"@"+addr+":"+remotePath)
cmd := exec.Command("scp", args...)
output, err := cmd.CombinedOutput()
if err != nil {
return errors.New(string(output))
@ -370,6 +379,16 @@ func (q *System) CopyFile(user, localPath, remotePath string) (err error) {
return
}
// CopyFile from local machine to remote via scp
func (q System) CopyFile(user, localPath, remotePath string) (err error) {
return q.scp(user, localPath, remotePath, false)
}
// CopyDirectory from local machine to remote via scp
func (q System) CopyDirectory(user, localPath, remotePath string) (err error) {
return q.scp(user, localPath, remotePath, true)
}
// CopyAndInsmod copy kernel module to temporary file on qemu then insmod it
func (q *System) CopyAndInsmod(localKoPath string) (output string, err error) {
remoteKoPath := fmt.Sprintf("/tmp/module_%d.ko", rand.Int())