Skip to content

Commit

Permalink
Chrome: Rename _is_valid_{file,dir} -> _{file,directory}_is_accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
cakekoa authored and ilija-lazoroski committed Sep 11, 2023
1 parent 3556f3e commit 1f6c3e3
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ def _get_login_data_paths(self, profile_dir_path: PurePath) -> Sequence[PurePath
sub_profile_dirs = Path(profile_dir_path).iterdir()
for subdir in sub_profile_dirs:
if subdir == (profile_dir_path / LOGIN_DATABASE_FILENAME):
if self._is_valid_file(subdir):
if self._file_is_accessible(subdir):
login_data_paths.append(PurePath(subdir))

login_database_path = profile_dir_path / subdir / LOGIN_DATABASE_FILENAME
if self._is_valid_file(login_database_path):
if self._file_is_accessible(login_database_path):
login_data_paths.append(login_database_path)
except Exception as err:
logger.debug(f"Could not list {profile_dir_path}: {err}")

return login_data_paths

def _is_valid_file(self, path: PurePath) -> bool:
@staticmethod
def _file_is_accessible(path: PurePath) -> bool:
try:
return Path(path).is_file() and os.access(path, os.R_OK)
except PermissionError as err:
Expand All @@ -65,7 +66,7 @@ def _get_browser_database_paths(self) -> Sequence[PurePath]:
for browser_name, browser_path in CHROMIUM_BASED_DB_PATHS:
browser_db_path = home_dir_path / browser_path
try:
if self._is_valid_dir(browser_db_path):
if self._directory_is_accessible(browser_db_path):
database_paths.append(browser_db_path)
except Exception as err:
logger.exception(
Expand All @@ -74,14 +75,16 @@ def _get_browser_database_paths(self) -> Sequence[PurePath]:

return database_paths

def _is_valid_dir(self, path: PurePath) -> bool:
@staticmethod
def _directory_is_accessible(path: PurePath) -> bool:
try:
return Path(path).is_dir() and os.access(path, os.R_OK)
except PermissionError as err:
logger.debug(f"Failed to validate path {path}: {err}")
return False

def _get_home_directories(self) -> UserDirectories:
@staticmethod
def _get_home_directories() -> UserDirectories:
"""
Retrieve all users' home directories
"""
Expand Down

0 comments on commit 1f6c3e3

Please sign in to comment.