diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index ddbf4348..d030fbfa 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2410161545 +v5.0.0-beta-2410222247 diff --git a/hrp/pkg/gadb/device.go b/hrp/pkg/gadb/device.go index 4d743214..9f73c10d 100644 --- a/hrp/pkg/gadb/device.go +++ b/hrp/pkg/gadb/device.go @@ -508,16 +508,22 @@ func (d *Device) List(remotePath string) (devFileInfos []DeviceFileInfo, err err return } -func (d *Device) PushFile(local *os.File, remotePath string, modification ...time.Time) (err error) { +func (d *Device) PushFile(localPath, remotePath string, modification ...time.Time) (err error) { + localFile, err := os.Open(localPath) + if err != nil { + return err + } + defer localFile.Close() + if len(modification) == 0 { var stat os.FileInfo - if stat, err = local.Stat(); err != nil { + if stat, err = localFile.Stat(); err != nil { return err } modification = []time.Time{stat.ModTime()} } - return d.Push(local, remotePath, modification[0], DefaultFileMode) + return d.Push(localFile, remotePath, modification[0], DefaultFileMode) } func (d *Device) Push(source io.Reader, remotePath string, modification time.Time, mode ...os.FileMode) (err error) { diff --git a/hrp/pkg/gadb/device_test.go b/hrp/pkg/gadb/device_test.go index a8038e29..9f8be869 100644 --- a/hrp/pkg/gadb/device_test.go +++ b/hrp/pkg/gadb/device_test.go @@ -246,8 +246,8 @@ func TestDevice_Push(t *testing.T) { setupDevices(t) for _, dev := range devices { - file, _ := os.Open("/Users/hero/Documents/temp/MuMu共享文件夹/test.txt") - err := dev.PushFile(file, "/sdcard/Download/push.txt", time.Now()) + localPath := "test.txt" + err := dev.PushFile(localPath, "/sdcard/Download/push.txt", time.Now()) if err != nil { t.Fatal(err) } diff --git a/hrp/pkg/gadb/examples/main.go b/hrp/pkg/gadb/examples/main.go index e28094ec..23182707 100644 --- a/hrp/pkg/gadb/examples/main.go +++ b/hrp/pkg/gadb/examples/main.go @@ -3,6 +3,7 @@ package main import ( "log" "os" + "path/filepath" "strings" "github.com/httprunner/httprunner/v4/hrp/pkg/gadb" @@ -22,13 +23,12 @@ func main() { dev := devices[0] userHomeDir, _ := os.UserHomeDir() - apk, err := os.Open(userHomeDir + "/Desktop/xuexi_android_10002068.apk") - checkErr(err) + localPath := filepath.Join(userHomeDir, "xxx.apk") log.Println("starting to push apk") remotePath := "/data/local/tmp/xuexi_android_10002068.apk" - err = dev.PushFile(apk, remotePath) + err = dev.PushFile(localPath, remotePath) checkErr(err, "adb push") log.Println("push completed") @@ -42,7 +42,6 @@ func main() { } log.Println("install completed") - } func checkErr(err error, msg ...string) {