better-adb-sync
better-adb-sync copied to clipboard
Force to continue on permission denied error
Hello,
this is somewhat linked to #15, but not completely. I face the following error:
adbsync.py --del --show-progress pull /storage/emulated/0 /backup/primary/
ADB line not captured
ls: /storage/emulated/0/Android/data/org.videolan.vlc/files/medialib: Permission denied
Exiting
and I would like to have an option to still continue.
What I already tried is to create a regex for this error and raise a PermissionError, however, I was unable how to figure out how to just skip affected files...
diff --git a/src/ADBSync/FileSystems/Android.py b/src/ADBSync/FileSystems/Android.py
index a74acb9..a8e8565 100644
--- a/src/ADBSync/FileSystems/Android.py
+++ b/src/ADBSync/FileSystems/Android.py
@@ -52,6 +52,7 @@ class AndroidFileSystem(FileSystem):
$""", re.DOTALL | re.VERBOSE)
RE_NO_SUCH_FILE = re.compile("^.*: No such file or directory$")
+ RE_PERMISSION_DENIED = re.compile("^.*: Permission denied$")
RE_LS_NOT_A_DIRECTORY = re.compile("ls: .*: Not a directory$")
RE_TOTAL = re.compile("^total \\d+$")
@@ -118,7 +119,9 @@ class AndroidFileSystem(FileSystem):
raise BrokenPipeError
def ls_to_stat(self, line: str) -> Tuple[str, os.stat_result]:
- if self.RE_NO_SUCH_FILE.fullmatch(line):
+ if self.RE_PERMISSION_DENIED.fullmatch(line):
+ raise PermissionError
+ elif self.RE_NO_SUCH_FILE.fullmatch(line):
raise FileNotFoundError
elif self.RE_LS_NOT_A_DIRECTORY.fullmatch(line):
raise NotADirectoryError
Ideal would be an option to just ignore such errors and still sync the rest.
Thanks Sebastian
I now fixed it for me:
https://github.com/Sebbb/better-adb-sync/commit/ff1be14e74a039100648141040d8c0c5dd22ebce
I don't think this code is nice enough to create a pull request, however, feel free to have a look. Maybe it helps others :)
Sebastian
I am In the need of ignoring any file read error. I am trying to recover a damaged sd card, and not all files are readdable. Waiting for a file to fail andthen adding it to the list of ignores is not very nice. An option to ignore X error would be awesome
That absolutely fixed my problem! Thank you so much
(.venv) nfinch@nfinchs-MBP BetterADBSync % adbsync pull /storage/emulated/0 ~/AndroidMay272024
Skipping file /storage/emulated/0/Android/data/com.android.systemui: PermissionError