Skip to content

Instantly share code, notes, and snippets.

@nikolay-n
Created December 4, 2020 17:19
Show Gist options
  • Save nikolay-n/3e00a6f9b47a8fda24734e065894c909 to your computer and use it in GitHub Desktop.
Save nikolay-n/3e00a6f9b47a8fda24734e065894c909 to your computer and use it in GitHub Desktop.
Wiggle permissions error fix "wiggle/agent/scanner.py"
import os
import pathlib
import logging
from agent.importer import add
class Scanner(object):
def __init__(self, directories, model, sysroot='/', block_list=None):
self.directories = map(pathlib.Path, directories)
self.sysroot = pathlib.Path(sysroot)
self.model = model
if block_list == None:
self.block_list = []
else:
self.block_list = set(map(pathlib.Path, block_list))
def run(self):
for path in self.directories:
try:
self.scan(path)
except (PermissionError):
logging.warning('!!Unable to read directory %s', path)
except FileNotFoundError as e:
logging.warning('!!Not found %s', path)
def scan(self, cwd):
from django.db import IntegrityError
for blocked in self.block_list:
if blocked == cwd or blocked in cwd.parents:
return
for child in cwd.iterdir():
try:
if child.is_dir():
try:
self.scan(child)
except PermissionError:
logging.warning('!Unable to read directory %s', child)
elif child.is_symlink():
# TODO: better solution for symlink
continue
elif child.is_file():
try:
add(child.resolve(), self)
except IntegrityError as e:
logging.error('Path %s may already exists\n(%s)', child, e)
except PermissionError as e:
logging.warning('Unable to read file %s\n(%s)', child, e)
except NotImplementedError as e:
logging.error('Unsupported file %s\n(%s)', child, e)
except PermissionError as e:
logging.warning('Unable to read path %s\n(%s)', child, e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment