Skip to content

Skip removing FIFOs from device #528

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

Merged
merged 5 commits into from
Oct 14, 2021

Conversation

eunikolsky
Copy link

That operation always fails with error 0xc anyway.

To distinguish regular files from FIFO, new READ_DIR_FIFO is added to
read_dir_cb_reason. The behavior of other operations regarding FIFOs
is left the same by supporting the new reason.

(Another implementation could be not to extend the read_dir_cb_reason
and add another flag to read_dir's callback, but that would allow
meaningless cases, such as reason = READ_DIR_AFTER_DIR, is_fifo = true.

The ideal implementation would be to extent the READ_DIR_FILE enum
case with a flag (i.e., READ_DIR_FILE(is_fifo = true)), but that is
not supported in Objective-C.)

The fix is to skip removing FIFOs had a side-effect of failing to remove
a directory where a skipped file is because the directory is not empty.

The change here is to continue removing files after errors, which is
also helpful in cases when ios-deploy fails to remove /Documents/
("Error 0xa: You do not have permission."), but still needs to continue
removing what it can from /Library/.

Fixes #518.

Error messages

I've also stumbled upon a fix for error messages (I can extract it to a new PR if necessary):

This makes ios-deploy print error messages for known error codes so
that the console log looks like:

ios-deploy[13450:4855044] [ !! ] Error 0x1: An unknown error occurred. AFCRemovePath(conn, name)
ios-deploy[13450:4855044] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)

instead of:

ios-deploy[13409:4853438] [ !! ] Error 0x1: unknown. AFCRemovePath(conn, name)
ios-deploy[13409:4853438] [ !! ] Error 0xa: unknown. AFCRemovePath(conn, name)

The fix is to create an error code from the input error to match
what's defined in errorcode_to_id (for some reason, the errors are
OR'd with 0xe8000000). This change is taken from the
SDMMobileDevice project, which is the source for the error codes.

Sample output now

$ ios-deploy -1 io.realm.Simple --rmtree /
[....] Waiting for iOS device to be connected
[....] Using X (J72bAP, iPad (2018), iphoneos, arm64, 14.4.1, 18D61) a.k.a. 'iPad'.
2021-07-26 16:48:58.257 ios-deploy[15159:4903131] [ !! ] Error 0x1: An unknown error occurred. AFCRemovePath(conn, name)
2021-07-26 16:48:58.294 ios-deploy[15159:4903131] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
2021-07-26 16:48:58.363 ios-deploy[15159:4903131] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
2021-07-26 16:48:58.469 ios-deploy[15159:4903131] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
2021-07-26 16:48:58.477 ios-deploy[15159:4903131] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
2021-07-26 16:48:58.497 ios-deploy[15159:4903131] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)

$ ios-deploy -1 io.realm.Simple -v --rmtree /
[....] Waiting for iOS device to be connected
Handling device type: 1
Already found device? 0
Hardware Model: J72bAP
Device Name: iPad
Model Name: iPad (2018)
SDK Name: iphoneos
Architecture Name: arm64
Product Version: 14.4.1
Build Version: 18D61
[....] Using X (J72bAP, iPad (2018), iphoneos, arm64, 14.4.1, 18D61) a.k.a. 'iPad'.
Skipping /Documents/default.realm.management/lock.fifo
Skipping /Documents/default.realm.management/access_control.write.mx.fifo
Skipping /Documents/default.realm.management/access_control.new_commit.cv
Deleting /Documents/default.realm.management/access_control.write.mx
Deleting /Documents/default.realm.management/access_control.control.mx
Skipping /Documents/default.realm.management/access_control.pick_writer.cv
Skipping /Documents/default.realm.management/access_control.control.mx.fifo
Deleting /Documents/default.realm.management
2021-07-26 16:49:33.700 ios-deploy[15616:4907374] [ !! ] Error 0x1: An unknown error occurred. AFCRemovePath(conn, name)
Deleting /Documents/default.realm
Deleting /Documents/default.realm.lock
Skipping /Documents/default.realm.note
Deleting /Documents
2021-07-26 16:49:33.732 ios-deploy[15616:4907374] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
Deleting /Library/Caches/io.realm.Simple/com.apple.metalfe
Deleting /Library/Caches/io.realm.Simple/Cache.db
Deleting /Library/Caches/io.realm.Simple/Cache.db-wal
Deleting /Library/Caches/io.realm.Simple/Cache.db-shm
Deleting /Library/Caches/io.realm.Simple
Deleting /Library/Caches
2021-07-26 16:49:33.810 ios-deploy[15616:4907374] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
Deleting /Library/Saved Application State/io.realm.Simple.savedState/KnownSceneSessions/data.data
Deleting /Library/Saved Application State/io.realm.Simple.savedState/KnownSceneSessions
Deleting /Library/Saved Application State/io.realm.Simple.savedState
Deleting /Library/Saved Application State
Deleting /Library/SplashBoard/Snapshots/io.realm.Simple - {DEFAULT GROUP}/E477E795-9DCD-4D7C-8419-E70B3A240F30@2x.ktx
Deleting /Library/SplashBoard/Snapshots/io.realm.Simple - {DEFAULT GROUP}/downscaled/563F34C5-8A7E-4AEF-8ECA-4CBD26879FAA@2x.ktx
Deleting /Library/SplashBoard/Snapshots/io.realm.Simple - {DEFAULT GROUP}/downscaled
Deleting /Library/SplashBoard/Snapshots/io.realm.Simple - {DEFAULT GROUP}
Deleting /Library/SplashBoard/Snapshots
Deleting /Library/SplashBoard
Deleting /Library/Preferences
2021-07-26 16:49:33.920 ios-deploy[15616:4907374] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
Deleting /Library
2021-07-26 16:49:33.927 ios-deploy[15616:4907374] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
Deleting /tmp
Deleting /
2021-07-26 16:49:33.947 ios-deploy[15616:4907374] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)

@ivanhernandez13
Copy link

Thanks for the PR and sorry for the delay. I'll try to check this out sometime early this week.

@ivanhernandez13 ivanhernandez13 self-requested a review September 13, 2021 16:05
That operation always fails with error `0xc` anyway.

To distinguish regular files from FIFO, new `READ_DIR_FIFO` is added to
`read_dir_cb_reason`. The behavior of other operations regarding FIFOs
is left the same by supporting the new reason.

Another implementation could be not to extend the `read_dir_cb_reason`
and add another flag to `read_dir`'s `callback`, but that would allow
meaningless cases, such as `reason = READ_DIR_AFTER_DIR, is_fifo =
true`.

The ideal implementation would be to extent the `READ_DIR_FILE` enum
case with a flag (i.e., `READ_DIR_FILE(is_fifo = true)`), but that is
not supported in Objective-C.
@eunikolsky eunikolsky force-pushed the fix/skip_removing_fifo branch 2 times, most recently from ffe3c40 to 2c4db43 Compare September 27, 2021 07:12
The fix is to skip removing FIFOs had a side-effect of failing to remove
a directory where a skipped file is because the directory is not empty.

The change here is to continue removing files after errors, which is
also helpful in cases when `ios-deploy` fails to remove `/Documents/`
("Error 0xa: You do not have permission."), but still needs to continue
removing what it can from `/Library/`.
This makes `ios-deploy` print error messages for known error codes so
that the console log looks like:

```
ios-deploy[13450:4855044] [ !! ] Error 0x1: An unknown error occurred. AFCRemovePath(conn, name)
ios-deploy[13450:4855044] [ !! ] Error 0xa: You do not have permission. AFCRemovePath(conn, name)
```

instead of:

```
ios-deploy[13409:4853438] [ !! ] Error 0x1: unknown. AFCRemovePath(conn, name)
ios-deploy[13409:4853438] [ !! ] Error 0xa: unknown. AFCRemovePath(conn, name)
```

The fix is to create an error code from the input `error` to match
what's defined in `errorcode_to_id` (for some reason, the errors are
`OR`'d with `0xe8000000`). This change is taken from the
`SDMMobileDevice` project, which is the source for the error codes.
@eunikolsky eunikolsky force-pushed the fix/skip_removing_fifo branch from 2c4db43 to e5915d2 Compare September 27, 2021 07:15
@eunikolsky
Copy link
Author

Rebased the branch onto latest master.

@MattCenturion
Copy link

We ran into the same issue where rmtree stops after permissions error and this PR fixes our usage. Thanks!

@gabebear gabebear merged commit 3591101 into ios-control:master Oct 14, 2021
@gabebear
Copy link

This makes sense, I don't have time to actually test this on real devices but I think it's better to get this merged since it's a real-world issue.

@eunikolsky eunikolsky deleted the fix/skip_removing_fifo branch October 14, 2021 16:11
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.

rmtree stops when failing to remove a FIFO on device
4 participants