Skip to content

Conversation

@dmissmann
Copy link
Collaborator

The current implementation has a lot of repeated code. Every method that communicates with the afc service on the device has it's own logic for building the package and maintaining the package identifiers.

This is now done in a single place that abstracts away of this logic that was repeated over and over before.

Also, file I/O works now similar to "regular" filesystems. When we open a file using the afc service, we get back a io.ReadWriteCloser, which allows us to use functions like io.Copy on those files.

return 0, fmt.Errorf("error reading data: %w", err)
}
resp, err := f.client.readPacket()
copy(p, resp.Payload)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
copy(p, resp.Payload)
if err != nil {
return 0, fmt.Errorf("error reading data: %w", err)
}
copy(p, resp.Payload)

if err != nil {
break
}
if len(s) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dmissmann AFC directories may contain "." and "..". It may cause infinite recursion or traversing outside the subtree that was requested

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was changed as you also did in the comment #627 (comment) the List method doesn't show those entries now and WalkDir won't see them when traversing the direcotry

if err != nil {
break
}
if len(s) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if len(s) == 0 {
if len(s) <= 1 {

Copy link
Collaborator Author

@dmissmann dmissmann Nov 25, 2025

Choose a reason for hiding this comment

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

There's now a local variable that cuts off the NULL-terminator and we can check again for 0 (like in the example you posted below 😄 )

if len(s) == 0 {
continue
}
list = append(list, s[:len(s)-1])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
list = append(list, s[:len(s)-1])
entry := s[:len(s)-1])
if entry == "." || entry == ".." {
continue
}
list = append(list, s[:len(s)-1])

@iSevenDays
Copy link
Collaborator

do I understand correctly that fsync --pull and --push only operate on single files now?
maybe in main.go:1136 we could use smth like

    _, err = io.Copy(local, remote)
    if dp == "" {
        dp = "."
}
err = afcService.Pull(sp, dp)

instead of

local, err := os.Create(path.Join(dp, filepath.Base(sp)))
exitIfError("failed to open local file", err)
defer local.Close()
remote, err := afcService.Open(sp, afc.READ_ONLY)

I think the pulling/pushing of directories may fail with AFC

c.deviceConn.Close()
func vendContainer(deviceConn ios.DeviceConnectionInterface, bundleID string) error {
plistCodec := ios.NewPlistCodec()
vendContainer := map[string]interface{}{"Command": "vendContainer", "Identifier": bundleID}
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't it be "VendContainer"? I'm not sure renaming changes here anything, just to confirm :)

@dmissmann
Copy link
Collaborator Author

do I understand correctly that fsync --pull and --push only operate on single files now? maybe in main.go:1136 we could use smth like

    _, err = io.Copy(local, remote)
    if dp == "" {
        dp = "."
}
err = afcService.Pull(sp, dp)

instead of

local, err := os.Create(path.Join(dp, filepath.Base(sp)))
exitIfError("failed to open local file", err)
defer local.Close()
remote, err := afcService.Open(sp, afc.READ_ONLY)

I think the pulling/pushing of directories may fail with AFC

I reverted the changes in main.go now and it works as before. And that was pulling works with directories as well, but pushing was always file-only

case errDirNotEmpty:
return errors.New("DirNotEmpty")
default:
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dmissmann maybe we should return an error here?

return fmt.Errorf("unknown AFC error code: %d", errorCode)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants