inotify.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:centos-base-consul 作者: zeroc0d3lab 项目源码 文件源码
def add_watches(self, base, top_level=True):
        ''' Add watches for this directory and all its descendant directories,
        recursively. '''
        base = realpath(base)
        # There may exist a link which leads to an endless
        # add_watches loop or to maximum recursion depth exceeded
        if not top_level and base in self.watched_dirs:
            return
        try:
            is_dir = self.add_watch(base)
        except OSError as e:
            if e.errno == errno.ENOENT:
                # The entry could have been deleted between listdir() and
                # add_watch().
                if top_level:
                    raise NoSuchDir('The dir {0} does not exist'.format(base))
                return
            if e.errno == errno.EACCES:
                # We silently ignore entries for which we dont have permission,
                # unless they are the top level dir
                if top_level:
                    raise NoSuchDir('You do not have permission to monitor {0}'.format(base))
                return
            raise
        else:
            if is_dir:
                try:
                    files = os.listdir(base)
                except OSError as e:
                    if e.errno in (errno.ENOTDIR, errno.ENOENT):
                        # The dir was deleted/replaced between the add_watch()
                        # and listdir()
                        if top_level:
                            raise NoSuchDir('The dir {0} does not exist'.format(base))
                        return
                    raise
                for x in files:
                    self.add_watches(os.path.join(base, x), top_level=False)
            elif top_level:
                # The top level dir is a file, not good.
                raise NoSuchDir('The dir {0} does not exist'.format(base))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号