1
0
mirror of https://github.com/google/adb-sync.git synced 2026-01-03 01:48:02 +00:00

Merge caching and listing directory contents.

This also removes reliance on Android version specific "ls" arguments,
fixing things for both N and M.
This commit is contained in:
Rudolf Polzer
2016-09-26 10:52:47 -04:00
parent f345a79f93
commit ba8f830d28

View File

@@ -215,14 +215,7 @@ class AdbFileSystem(object):
return True return True
def listdir(self, path): # os's name, so pylint: disable=g-bad-name def listdir(self, path): # os's name, so pylint: disable=g-bad-name
"""List the contents of a directory.""" """List the contents of a directory, caching them for later lstat calls."""
with self.Stdout(self.adb + [b'shell', _sprintf(b'ls -a1 %s',
self.QuoteArgument(path))]) as stdout:
for line in stdout:
yield line.rstrip(b'\r\n')
def CacheDirectoryLstat(self, path):
"""Cache lstat for a directory."""
with self.Stdout(self.adb + [b'shell', _sprintf(b'ls -al %s', with self.Stdout(self.adb + [b'shell', _sprintf(b'ls -al %s',
self.QuoteArgument(path + b'/'))]) as stdout: self.QuoteArgument(path + b'/'))]) as stdout:
for line in stdout: for line in stdout:
@@ -234,9 +227,10 @@ class AdbFileSystem(object):
except OSError: except OSError:
continue continue
if filename is None: if filename is None:
_print(b'Warning: could not cache %s', line) _print(b'Warning: could not parse %s', line)
else: else:
self.stat_cache[path + b'/' + filename] = statdata self.stat_cache[path + b'/' + filename] = statdata
yield filename
def lstat(self, path): # os's name, so pylint: disable=g-bad-name def lstat(self, path): # os's name, so pylint: disable=g-bad-name
"""Stat a file.""" """Stat a file."""
@@ -324,11 +318,6 @@ def BuildFileList(fs, path, prefix=b''):
files = list(fs.listdir(path)) files = list(fs.listdir(path))
except OSError: except OSError:
return return
try:
if hasattr(fs, 'CacheDirectoryLstat'):
fs.CacheDirectoryLstat(path)
except OSError:
_print(b'Warning: could not cache lstat for %s', path)
files.sort() files.sort()
for n in files: for n in files:
if n == b'.' or n == b'..': if n == b'.' or n == b'..':