better-adb-sync icon indicating copy to clipboard operation
better-adb-sync copied to clipboard

Force to continue on permission denied error

Open Sebbb opened this issue 1 year ago • 3 comments

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

Sebbb avatar Apr 20 '23 12:04 Sebbb

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

Sebbb avatar Apr 20 '23 17:04 Sebbb

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

danielo515 avatar Jul 19 '23 22:07 danielo515

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

tisaconundrum2 avatar May 27 '24 14:05 tisaconundrum2