mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +08:00
feat: add PullFiles for ADBDriver
This commit is contained in:
@@ -961,6 +961,55 @@ func (ad *ADBDriver) ClearImages() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ad *ADBDriver) PullFiles(localDir string, remoteDirs ...string) error {
|
||||
log.Info().Str("localDir", localDir).Strs("remoteDirs", remoteDirs).Msg("ADBDriver.PullFiles")
|
||||
|
||||
// create local directory if not exists
|
||||
if err := os.MkdirAll(localDir, 0o755); err != nil {
|
||||
return fmt.Errorf("failed to create local directory: %w", err)
|
||||
}
|
||||
|
||||
for _, remoteDir := range remoteDirs {
|
||||
files, err := ad.Device.List(remoteDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list directory %s: %w", remoteDir, err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
remotePath := path.Join(remoteDir, file.Name)
|
||||
localPath := path.Join(localDir, file.Name)
|
||||
|
||||
// check if file already exists
|
||||
if _, err := os.Stat(localPath); err == nil {
|
||||
log.Debug().Str("localPath", localPath).Msg("file already exists, skipping")
|
||||
continue
|
||||
}
|
||||
|
||||
// create local file
|
||||
f, err := os.Create(localPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("localPath", localPath).Msg("failed to create local file")
|
||||
continue
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// pull image file
|
||||
if err := ad.Device.Pull(remotePath, f); err != nil {
|
||||
log.Error().Err(err).
|
||||
Str("remotePath", remotePath).
|
||||
Str("localPath", localPath).
|
||||
Msg("failed to pull file")
|
||||
continue // continue with next file
|
||||
}
|
||||
log.Info().
|
||||
Str("remotePath", remotePath).
|
||||
Str("localPath", localPath).
|
||||
Msg("file pulled successfully")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ad *ADBDriver) ClearFiles(paths ...string) error {
|
||||
log.Info().Strs("paths", paths).Msg("ADBDriver.ClearFiles")
|
||||
for _, path := range paths {
|
||||
|
||||
Reference in New Issue
Block a user