Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failure on installing large ipa: send packet (afc): write unix ->… #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions afc.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *afc) RemoveAll(path string) (err error) {
return
}

func (c *afc) WriteFile(filename string, data []byte, perm AfcFileMode) (err error) {
func (c *afc) WriteFile(filename string, r io.Reader, perm AfcFileMode) (err error) {
var file *AfcFile
if file, err = c.Open(filename, perm); err != nil {
return err
Expand All @@ -298,7 +298,7 @@ func (c *afc) WriteFile(filename string, data []byte, perm AfcFileMode) (err err
err = file.Close()
}()

if _, err = file.Write(data); err != nil {
if _, err = io.Copy(file, r); err != nil {
return err
}
return
Expand Down
11 changes: 4 additions & 7 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,9 @@ func (d *device) AppInstall(ipaPath string) (err error) {

installationPath := path.Join(stagingPath, fmt.Sprintf("%s.ipa", bundleID))

var data []byte
if data, err = os.ReadFile(ipaPath); err != nil {
return err
}
if err = d.afc.WriteFile(installationPath, data, AfcFileModeWr); err != nil {
return err
if r, err := os.Open(ipaPath); err != nil {return err} else {
defer r.Close()
if err = d.afc.WriteFile(installationPath, r, AfcFileModeWr); err != nil {return err}
}
Comment on lines +417 to 420
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 It would be better to close the file as soon as possible

	_ipaFile, err := os.Open(ipaPath)
	if err != nil {
		return err
	}
	if err = d.afc.WriteFile(installationPath, _ipaFile, AfcFileModeWr); err != nil {
		_ipaFile.Close()
		return err
	}
	_ipaFile.Close()


if _, err = d.installationProxyService(); err != nil {
Expand Down Expand Up @@ -831,7 +828,7 @@ func (d *device) _uploadXCTestConfiguration(bundleID string, sessionId uuid.UUID
return "", err
}

if err = appAfc.WriteFile(pathXCTestCfg, content, AfcFileModeWr); err != nil {
if err = appAfc.WriteFile(pathXCTestCfg, bytes.NewReader(content), AfcFileModeWr); err != nil {
return "", err
}

Expand Down
3 changes: 2 additions & 1 deletion idevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"log"
"time"

Expand Down Expand Up @@ -183,7 +184,7 @@ type Afc interface {
HashWithRange(filePath string, start, end uint64) ([]byte, error)
RemoveAll(path string) (err error)

WriteFile(filename string, data []byte, perm AfcFileMode) (err error)
WriteFile(filename string, r io.Reader, perm AfcFileMode) (err error)
}

type HouseArrest interface {
Expand Down