Python os.lstat() Examples

The following are 30 code examples for showing how to use os.lstat(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module os , or try the search function .

Example 1
Project: ANGRYsearch   Author: DoTheEvo   File: scandir.py    License: GNU General Public License v2.0 6 votes vote down vote up
def stat(self, follow_symlinks=True):
            if follow_symlinks:
                if self._stat is None:
                    if self.is_symlink():
                        # It's a symlink, call link-following stat()
                        self._stat = stat(self.path)
                    else:
                        # Not a symlink, stat is same as lstat value
                        if self._lstat is None:
                            self._lstat = find_data_to_stat(self._find_data)
                        self._stat = self._lstat
                return self._stat
            else:
                if self._lstat is None:
                    # Lazily convert to stat object, because it's slow
                    # in Python, and often we only need is_dir() etc
                    self._lstat = find_data_to_stat(self._find_data)
                return self._lstat 
Example 2
Project: jawfish   Author: war-and-code   File: shutil.py    License: MIT License 6 votes vote down vote up
def copymode(src, dst, *, follow_symlinks=True):
    """Copy mode bits from src to dst.

    If follow_symlinks is not set, symlinks aren't followed if and only
    if both `src` and `dst` are symlinks.  If `lchmod` isn't available
    (e.g. Linux) this method does nothing.

    """
    if not follow_symlinks and os.path.islink(src) and os.path.islink(dst):
        if hasattr(os, 'lchmod'):
            stat_func, chmod_func = os.lstat, os.lchmod
        else:
            return
    elif hasattr(os, 'chmod'):
        stat_func, chmod_func = os.stat, os.chmod
    else:
        return

    st = stat_func(src)
    chmod_func(dst, stat.S_IMODE(st.st_mode)) 
Example 3
Project: rekall   Author: google   File: cache.py    License: GNU General Public License v2.0 6 votes vote down vote up
def list_files(self, path):
        containing_dir_path = os.path.join(
            self.cache_directory, path.lstrip(os.path.sep))
        try:
            for root, _, files in os.walk(containing_dir_path):
                for filename in files:
                    if filename.startswith("@") and filename.endswith("@"):
                        generation = filename[1:-1]
                        subpath = "/" + os.path.relpath(
                            root, self.cache_directory)

                        s = os.lstat(os.path.join(root, filename))
                        yield dict(
                            created=s.st_ctime,
                            updated=s.st_mtime,
                            size=s.st_size,
                            generation=generation,
                            path=subpath)

        except (IOError, OSError):
            pass 
Example 4
Project: rekall   Author: google   File: common.py    License: GNU General Public License v2.0 6 votes vote down vote up
def from_stat(cls, filespec, session=None):
        filespec = FileSpec(filespec)
        result = FileInformation(filename=filespec, session=session)

        try:
            path = filespec.os_path()
            s = os.lstat(path)
        except (IOError, OSError) as e:
            return obj.NoneObject("Unable to stat %s", e)

        result.st_mode = Permissions(s.st_mode)
        result.st_ino = s.st_ino
        result.st_size = s.st_size
        result.st_dev = s.st_dev
        result.st_nlink = s.st_nlink
        result.st_uid = User.from_uid(s.st_uid)
        result.st_gid = Group.from_gid(s.st_gid)
        result.st_mtime = s.st_mtime
        result.st_atime = s.st_atime
        result.st_ctime = s.st_ctime

        return result 
Example 5
Project: ironpython2   Author: IronLanguages   File: test_posixpath.py    License: Apache License 2.0 6 votes vote down vote up
def test_ismount_different_device(self):
        # Simulate the path being on a different device from its parent by
        # mocking out st_dev.
        save_lstat = os.lstat
        def fake_lstat(path):
            st_ino = 0
            st_dev = 0
            if path == ABSTFN:
                st_dev = 1
                st_ino = 1
            return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
        try:
            os.lstat = fake_lstat
            self.assertIs(posixpath.ismount(ABSTFN), True)
        finally:
            os.lstat = save_lstat 
Example 6
Project: ironpython2   Author: IronLanguages   File: __init__.py    License: Apache License 2.0 6 votes vote down vote up
def _rmtree(path):
        try:
            shutil.rmtree(path)
            return
        except EnvironmentError:
            pass

        def _rmtree_inner(path):
            for name in _force_run(path, os.listdir, path):
                fullname = os.path.join(path, name)
                try:
                    mode = os.lstat(fullname).st_mode
                except EnvironmentError:
                    mode = 0
                if stat.S_ISDIR(mode):
                    _rmtree_inner(fullname)
                    _force_run(path, os.rmdir, fullname)
                else:
                    _force_run(path, os.unlink, fullname)
        _rmtree_inner(path)
        os.rmdir(path) 
Example 7
Project: agentless-system-crawler   Author: cloudviz   File: config_utils.py    License: Apache License 2.0 6 votes vote down vote up
def discover_config_file_paths(accessed_since, config_file_set,
                               exclude_regex, root_dir):
    # Walk the directory hierarchy starting at 'root_dir' in BFS
    # order looking for config files.
    for (root_dirpath, dirs, files) in os.walk(root_dir):
        dirs[:] = [os.path.join(root_dirpath, d) for d in
                   dirs]
        dirs[:] = [d for d in dirs
                   if not re.match(exclude_regex, d)]
        files = [os.path.join(root_dirpath, f) for f in
                 files]
        files = [f for f in files
                 if not re.match(exclude_regex, f)]
        for fpath in files:
            if os.path.exists(fpath) \
                    and _is_config_file(fpath):
                lstat = os.lstat(fpath)
                if lstat.st_atime > accessed_since \
                        or lstat.st_ctime > accessed_since:
                    config_file_set.add(fpath) 
Example 8
Project: smbprotocol   Author: jborean93   File: shutil.py    License: MIT License 5 votes vote down vote up
def _get_file_stat(path, follow_symlinks=True, **kwargs):
    if path.startswith('//') or path.startswith('\\\\'):
        return smbclient_stat(path, follow_symlinks=follow_symlinks, **kwargs)
    else:
        # Source is a local path or accessible to the host, use the builtin os module to get the read only flag.
        if follow_symlinks:
            return os.stat(path)
        else:
            return os.lstat(path) 
Example 9
Project: smbprotocol   Author: jborean93   File: test_smbclient_shutil.py    License: MIT License 5 votes vote down vote up
def test_copymode_local_to_local_symlink_follow(tmpdir):
    test_dir = tmpdir.mkdir('test')
    src_filename = "%s\\source.txt" % test_dir
    dst_filename = "%s\\target.txt" % test_dir

    with open(src_filename, mode='w') as fd:
        fd.write(u"content")
    os.chmod(src_filename, stat.S_IREAD)

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    src_link = "%s\\source-link.txt" % test_dir
    dst_link = "%s\\target-link.txt" % test_dir

    os.symlink(src_filename, src_link)
    os.symlink(dst_filename, dst_link)

    copymode(src_link, dst_link)

    actual_file = os.stat(dst_filename).st_mode
    assert stat.S_IMODE(actual_file) & stat.S_IWRITE == 0

    actual_link = os.lstat(dst_link).st_mode
    assert stat.S_IMODE(actual_link) & stat.S_IWRITE == stat.S_IWRITE

    os.chmod(src_filename, stat.S_IWRITE)  # Needed when running on Windows as os.remove will fail to remove.
    os.remove(src_filename)
    with open(src_filename, mode='w') as fd:
        fd.write(u"content")

    copymode(src_link, dst_link)

    actual_file = os.stat(dst_filename).st_mode
    assert stat.S_IMODE(actual_file) & stat.S_IWRITE == stat.S_IWRITE

    actual_link = os.lstat(dst_link).st_mode
    assert stat.S_IMODE(actual_link) & stat.S_IWRITE == stat.S_IWRITE 
Example 10
Project: smbprotocol   Author: jborean93   File: test_smbclient_shutil.py    License: MIT License 5 votes vote down vote up
def test_copystat_local_to_local_symlink_follow(tmpdir):
    test_dir = tmpdir.mkdir('test')
    src_filename = "%s\\source.txt" % test_dir
    dst_filename = "%s\\target.txt" % test_dir

    with open(src_filename, mode='w') as fd:
        fd.write(u"content")
    os.chmod(src_filename, stat.S_IREAD)
    os.utime(src_filename, (1024, 1024))

    with open(dst_filename, mode='w') as fd:
        fd.write(u"content")

    src_link = "%s\\source-link.txt" % test_dir
    dst_link = "%s\\target-link.txt" % test_dir

    os.symlink(src_filename, src_link)
    os.symlink(dst_filename, dst_link)

    copystat(src_link, dst_link)

    actual_file = os.stat(dst_filename)
    assert actual_file.st_atime == 1024
    assert actual_file.st_mtime == 1024
    assert stat.S_IMODE(actual_file.st_mode) & stat.S_IWRITE == 0

    actual_link = os.lstat(dst_link)
    assert actual_link.st_atime != 1024
    assert actual_link.st_mtime != 1024
    assert stat.S_IMODE(actual_link.st_mode) & stat.S_IWRITE == stat.S_IWRITE 
Example 11
Project: ANGRYsearch   Author: DoTheEvo   File: scandir.py    License: GNU General Public License v2.0 5 votes vote down vote up
def stat(self, follow_symlinks=True):
        if follow_symlinks:
            if self._stat is None:
                self._stat = stat(self.path)
            return self._stat
        else:
            if self._lstat is None:
                self._lstat = lstat(self.path)
            return self._lstat 
Example 12
Project: ANGRYsearch   Author: DoTheEvo   File: scandir.py    License: GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, scandir_path, name, lstat):
                self._scandir_path = scandir_path
                self.name = name
                self._stat = None
                self._lstat = lstat
                self._path = None 
Example 13
Project: ANGRYsearch   Author: DoTheEvo   File: scandir.py    License: GNU General Public License v2.0 5 votes vote down vote up
def stat(self, follow_symlinks=True):
            if follow_symlinks:
                if self._stat is None:
                    if self.is_symlink():
                        self._stat = stat(self.path)
                    else:
                        if self._lstat is None:
                            self._lstat = lstat(self.path)
                        self._stat = self._lstat
                return self._stat
            else:
                if self._lstat is None:
                    self._lstat = lstat(self.path)
                return self._lstat 
Example 14
Project: jawfish   Author: war-and-code   File: shutil.py    License: MIT License 5 votes vote down vote up
def _rmtree_unsafe(path, onerror):
    try:
        if os.path.islink(path):
            # symlinks to directories are forbidden, see bug #1669
            raise OSError("Cannot call rmtree on a symbolic link")
    except OSError:
        onerror(os.path.islink, path, sys.exc_info())
        # can't continue even if onerror hook returns
        return
    names = []
    try:
        names = os.listdir(path)
    except os.error:
        onerror(os.listdir, path, sys.exc_info())
    for name in names:
        fullname = os.path.join(path, name)
        try:
            mode = os.lstat(fullname).st_mode
        except os.error:
            mode = 0
        if stat.S_ISDIR(mode):
            _rmtree_unsafe(fullname, onerror)
        else:
            try:
                os.unlink(fullname)
            except os.error:
                onerror(os.unlink, fullname, sys.exc_info())
    try:
        os.rmdir(path)
    except os.error:
        onerror(os.rmdir, path, sys.exc_info())

# Version using fd-based APIs to protect against races 
Example 15
Project: jawfish   Author: war-and-code   File: posixpath.py    License: MIT License 5 votes vote down vote up
def dirname(p):
    """Returns the directory component of a pathname"""
    sep = _get_sep(p)
    i = p.rfind(sep) + 1
    head = p[:i]
    if head and head != sep*len(head):
        head = head.rstrip(sep)
    return head


# Is a path a symbolic link?
# This will always return false on systems where os.lstat doesn't exist. 
Example 16
Project: jawfish   Author: war-and-code   File: posixpath.py    License: MIT License 5 votes vote down vote up
def islink(path):
    """Test whether a path is a symbolic link"""
    try:
        st = os.lstat(path)
    except (os.error, AttributeError):
        return False
    return stat.S_ISLNK(st.st_mode)

# Being true for dangling symbolic links is also useful. 
Example 17
Project: jawfish   Author: war-and-code   File: posixpath.py    License: MIT License 5 votes vote down vote up
def sameopenfile(fp1, fp2):
    """Test whether two open file objects reference the same file"""
    s1 = os.fstat(fp1)
    s2 = os.fstat(fp2)
    return samestat(s1, s2)


# Are two stat buffers (obtained from stat, fstat or lstat)
# describing the same file? 
Example 18
Project: jawfish   Author: war-and-code   File: posixpath.py    License: MIT License 5 votes vote down vote up
def ismount(path):
    """Test whether a path is a mount point"""
    if islink(path):
        # A symlink can never be a mount point
        return False
    try:
        s1 = os.lstat(path)
        if isinstance(path, bytes):
            parent = join(path, b'..')
        else:
            parent = join(path, '..')
        s2 = os.lstat(parent)
    except os.error:
        return False # It doesn't exist -- so not a mount point :-)
    dev1 = s1.st_dev
    dev2 = s2.st_dev
    if dev1 != dev2:
        return True     # path/.. on a different device as path
    ino1 = s1.st_ino
    ino2 = s2.st_ino
    if ino1 == ino2:
        return True     # path/.. is the same i-node as path
    return False


# Expand paths beginning with '~' or '~user'.
# '~' means $HOME; '~user' means that user's home directory.
# If the path doesn't begin with '~', or if the user or $HOME is unknown,
# the path is returned unchanged (leaving error reporting to whatever
# function is called with the expanded path as argument).
# See also module 'glob' for expansion of *, ? and [...] in pathnames.
# (A function should also be defined to do full *sh-style environment
# variable expansion.) 
Example 19
Project: me-ica   Author: ME-ICA   File: dft.py    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
def _update_dir(c, dir, files, studies, series, storage_instances):
    logger.debug('Updating directory %s' % dir)
    c.execute("SELECT name, mtime FROM file WHERE directory = ?", (dir, ))
    db_mtimes = dict(c)
    for fname in db_mtimes:
        if fname not in files:
            logger.debug('    remove %s' % fname)
            c.execute("DELETE FROM file WHERE directory = ? AND name = ?", 
                      (dir, fname))
    for fname in files:
        mtime = os.lstat('%s/%s' % (dir, fname)).st_mtime
        if fname in db_mtimes and mtime <= db_mtimes[fname]:
            logger.debug('    okay %s' % fname)
        else:
            logger.debug('    update %s' % fname)
            si_uid = _update_file(c, dir, fname, studies, series, storage_instances)
            if fname not in db_mtimes:
                query = """INSERT INTO file (directory, 
                                             name, 
                                             mtime, 
                                             storage_instance) 
                           VALUES (?, ?, ?, ?)"""
                c.execute(query, (dir, fname, mtime, si_uid))
            else:
                query = """UPDATE file 
                              SET mtime = ?, storage_instance = ? 
                            WHERE directory = ? AND name = ?"""
                c.execute(query, (mtime, si_uid, dir, fname))
    return 
Example 20
Project: misp42splunk   Author: remg427   File: bccache.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def _get_default_cache_dir(self):
        def _unsafe_dir():
            raise RuntimeError('Cannot determine safe temp directory.  You '
                               'need to explicitly provide one.')

        tmpdir = tempfile.gettempdir()

        # On windows the temporary directory is used specific unless
        # explicitly forced otherwise.  We can just use that.
        if os.name == 'nt':
            return tmpdir
        if not hasattr(os, 'getuid'):
            _unsafe_dir()

        dirname = '_jinja2-cache-%d' % os.getuid()
        actual_dir = os.path.join(tmpdir, dirname)

        try:
            os.mkdir(actual_dir, stat.S_IRWXU)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        try:
            os.chmod(actual_dir, stat.S_IRWXU)
            actual_dir_stat = os.lstat(actual_dir)
            if actual_dir_stat.st_uid != os.getuid() \
               or not stat.S_ISDIR(actual_dir_stat.st_mode) \
               or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
                _unsafe_dir()
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        actual_dir_stat = os.lstat(actual_dir)
        if actual_dir_stat.st_uid != os.getuid() \
           or not stat.S_ISDIR(actual_dir_stat.st_mode) \
           or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
            _unsafe_dir()

        return actual_dir 
Example 21
Project: misp42splunk   Author: remg427   File: bccache.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def _get_default_cache_dir(self):
        def _unsafe_dir():
            raise RuntimeError('Cannot determine safe temp directory.  You '
                               'need to explicitly provide one.')

        tmpdir = tempfile.gettempdir()

        # On windows the temporary directory is used specific unless
        # explicitly forced otherwise.  We can just use that.
        if os.name == 'nt':
            return tmpdir
        if not hasattr(os, 'getuid'):
            _unsafe_dir()

        dirname = '_jinja2-cache-%d' % os.getuid()
        actual_dir = os.path.join(tmpdir, dirname)

        try:
            os.mkdir(actual_dir, stat.S_IRWXU)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        try:
            os.chmod(actual_dir, stat.S_IRWXU)
            actual_dir_stat = os.lstat(actual_dir)
            if actual_dir_stat.st_uid != os.getuid() \
               or not stat.S_ISDIR(actual_dir_stat.st_mode) \
               or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
                _unsafe_dir()
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        actual_dir_stat = os.lstat(actual_dir)
        if actual_dir_stat.st_uid != os.getuid() \
           or not stat.S_ISDIR(actual_dir_stat.st_mode) \
           or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
            _unsafe_dir()

        return actual_dir 
Example 22
Project: py   Author: pytest-dev   File: local.py    License: MIT License 5 votes vote down vote up
def islink(self):
        st = self.path.lstat()
        return S_ISLNK(self._osstatresult.st_mode) 
Example 23
Project: py   Author: pytest-dev   File: local.py    License: MIT License 5 votes vote down vote up
def _stat(self):
            try:
                return self._statcache
            except AttributeError:
                try:
                    self._statcache = self.path.stat()
                except py.error.ELOOP:
                    self._statcache = self.path.lstat()
                return self._statcache 
Example 24
Project: py   Author: pytest-dev   File: local.py    License: MIT License 5 votes vote down vote up
def link(self):
            st = self.path.lstat()
            return S_ISLNK(st.mode) 
Example 25
Project: py   Author: pytest-dev   File: local.py    License: MIT License 5 votes vote down vote up
def lstat(self):
        """ Return an os.lstat() tuple. """
        return Stat(self, py.error.checked_call(os.lstat, self.strpath)) 
Example 26
Project: recruit   Author: Frank-qlu   File: bccache.py    License: Apache License 2.0 5 votes vote down vote up
def _get_default_cache_dir(self):
        def _unsafe_dir():
            raise RuntimeError('Cannot determine safe temp directory.  You '
                               'need to explicitly provide one.')

        tmpdir = tempfile.gettempdir()

        # On windows the temporary directory is used specific unless
        # explicitly forced otherwise.  We can just use that.
        if os.name == 'nt':
            return tmpdir
        if not hasattr(os, 'getuid'):
            _unsafe_dir()

        dirname = '_jinja2-cache-%d' % os.getuid()
        actual_dir = os.path.join(tmpdir, dirname)

        try:
            os.mkdir(actual_dir, stat.S_IRWXU)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        try:
            os.chmod(actual_dir, stat.S_IRWXU)
            actual_dir_stat = os.lstat(actual_dir)
            if actual_dir_stat.st_uid != os.getuid() \
               or not stat.S_ISDIR(actual_dir_stat.st_mode) \
               or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
                _unsafe_dir()
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        actual_dir_stat = os.lstat(actual_dir)
        if actual_dir_stat.st_uid != os.getuid() \
           or not stat.S_ISDIR(actual_dir_stat.st_mode) \
           or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
            _unsafe_dir()

        return actual_dir 
Example 27
Project: recruit   Author: Frank-qlu   File: bccache.py    License: Apache License 2.0 5 votes vote down vote up
def _get_default_cache_dir(self):
        def _unsafe_dir():
            raise RuntimeError('Cannot determine safe temp directory.  You '
                               'need to explicitly provide one.')

        tmpdir = tempfile.gettempdir()

        # On windows the temporary directory is used specific unless
        # explicitly forced otherwise.  We can just use that.
        if os.name == 'nt':
            return tmpdir
        if not hasattr(os, 'getuid'):
            _unsafe_dir()

        dirname = '_jinja2-cache-%d' % os.getuid()
        actual_dir = os.path.join(tmpdir, dirname)

        try:
            os.mkdir(actual_dir, stat.S_IRWXU)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        try:
            os.chmod(actual_dir, stat.S_IRWXU)
            actual_dir_stat = os.lstat(actual_dir)
            if actual_dir_stat.st_uid != os.getuid() \
               or not stat.S_ISDIR(actual_dir_stat.st_mode) \
               or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
                _unsafe_dir()
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        actual_dir_stat = os.lstat(actual_dir)
        if actual_dir_stat.st_uid != os.getuid() \
           or not stat.S_ISDIR(actual_dir_stat.st_mode) \
           or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
            _unsafe_dir()

        return actual_dir 
Example 28
Project: jbox   Author: jpush   File: bccache.py    License: MIT License 5 votes vote down vote up
def _get_default_cache_dir(self):
        def _unsafe_dir():
            raise RuntimeError('Cannot determine safe temp directory.  You '
                               'need to explicitly provide one.')

        tmpdir = tempfile.gettempdir()

        # On windows the temporary directory is used specific unless
        # explicitly forced otherwise.  We can just use that.
        if os.name == 'nt':
            return tmpdir
        if not hasattr(os, 'getuid'):
            _unsafe_dir()

        dirname = '_jinja2-cache-%d' % os.getuid()
        actual_dir = os.path.join(tmpdir, dirname)

        try:
            os.mkdir(actual_dir, stat.S_IRWXU)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        try:
            os.chmod(actual_dir, stat.S_IRWXU)
            actual_dir_stat = os.lstat(actual_dir)
            if actual_dir_stat.st_uid != os.getuid() \
               or not stat.S_ISDIR(actual_dir_stat.st_mode) \
               or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
                _unsafe_dir()
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        actual_dir_stat = os.lstat(actual_dir)
        if actual_dir_stat.st_uid != os.getuid() \
           or not stat.S_ISDIR(actual_dir_stat.st_mode) \
           or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
            _unsafe_dir()

        return actual_dir 
Example 29
Project: jbox   Author: jpush   File: easy_install.py    License: MIT License 5 votes vote down vote up
def rmtree(path, ignore_errors=False, onerror=auto_chmod):
    """Recursively delete a directory tree.

    This code is taken from the Python 2.4 version of 'shutil', because
    the 2.3 version doesn't really work right.
    """
    if ignore_errors:
        def onerror(*args):
            pass
    elif onerror is None:
        def onerror(*args):
            raise
    names = []
    try:
        names = os.listdir(path)
    except os.error:
        onerror(os.listdir, path, sys.exc_info())
    for name in names:
        fullname = os.path.join(path, name)
        try:
            mode = os.lstat(fullname).st_mode
        except os.error:
            mode = 0
        if stat.S_ISDIR(mode):
            rmtree(fullname, ignore_errors, onerror)
        else:
            try:
                os.remove(fullname)
            except os.error:
                onerror(os.remove, fullname, sys.exc_info())
    try:
        os.rmdir(path)
    except os.error:
        onerror(os.rmdir, path, sys.exc_info()) 
Example 30
Project: rekall   Author: google   File: cache.py    License: GNU General Public License v2.0 5 votes vote down vote up
def stat(self, path):
        generation = self.get_generation(path)
        if generation:
            subpath = self.get_local_file(path, generation)
            s = os.lstat(subpath)
            return dict(
                created=s.st_ctime,
                updated=s.st_mtime,
                size=s.st_size,
                generation=generation,
                path=path)