def _deleted_files():
    '''
    Iterates over /proc/PID/maps and /proc/PID/fd links and returns list of desired deleted files.

    Returns:
        List of deleted files to analyze, False on failure.

    '''
    deleted_files = []

    for proc in psutil.process_iter():  # pylint: disable=too-many-nested-blocks
        try:
            pinfo = proc.as_dict(attrs=['pid', 'name'])
            try:
                with salt.utils.files.fopen('/proc/{0}/maps'.format(pinfo['pid'])) as maps:  # pylint: disable=resource-leakage
                    dirpath = '/proc/' + six.text_type(pinfo['pid']) + '/fd/'
                    listdir = os.listdir(dirpath)
                    maplines = maps.readlines()
            except (OSError, IOError):
                yield False

            # /proc/PID/maps
            mapline = re.compile(r'^[\da-f]+-[\da-f]+ [r-][w-][x-][sp-] '
                                 r'[\da-f]+ [\da-f]{2}:[\da-f]{2} (\d+) *(.+)( \(deleted\))?\n$')

            for line in maplines:
                line = salt.utils.stringutils.to_unicode(line)
                matched = mapline.match(line)
                if not matched:
                    continue
                path = matched.group(2)
                if not path:
                    continue
                valid = _valid_deleted_file(path)
                if not valid:
                    continue
                val = (pinfo['name'], pinfo['pid'], path[0:-10])
                if val not in deleted_files:
                    deleted_files.append(val)
                    yield val

            # /proc/PID/fd
            try:
                for link in listdir:
                    path = dirpath + link
                    readlink = os.readlink(path)
                    filenames = []

                    if os.path.isfile(readlink):
                        filenames.append(readlink)
                    elif os.path.isdir(readlink) and readlink != '/':
                        for root, dummy_dirs, files in salt.utils.path.os_walk(readlink, followlinks=True):
                            for name in files:
                                filenames.append(os.path.join(root, name))

                    for filename in filenames:
                        valid = _valid_deleted_file(filename)
                        if not valid:
                            continue
                        val = (pinfo['name'], pinfo['pid'], filename)
                        if val not in deleted_files:
                            deleted_files.append(val)
                            yield val
            except OSError:
                pass

        except psutil.NoSuchProcess:
            pass
def _deleted_files ( ) : deleted_files = [ ] for proc in psutil . process_iter ( ) : try : pinfo = proc . as_dict ( attrs = [ 'pid' , 'name' ] ) try : with salt . utils . files . fopen ( '/proc/{0}/maps' . format ( pinfo [ 'pid' ] ) ) as maps : dirpath = '/proc/' + six . text_type ( pinfo [ 'pid' ] ) + '/fd/' listdir = os . listdir ( dirpath ) maplines = maps . readlines ( ) except ( OSError , IOError ) : yield False mapline = re . compile ( r'^[\da-f]+-[\da-f]+ [r-][w-][x-][sp-] ' r'[\da-f]+ [\da-f]{2}:[\da-f]{2} (\d+) *(.+)( \(deleted\))?\n$' ) for line in maplines : line = salt . utils . stringutils . to_unicode ( line ) matched = mapline . match ( line ) if not matched : continue path = matched . group ( 2 ) if not path : continue valid = _valid_deleted_file ( path ) if not valid : continue val = ( pinfo [ 'name' ] , pinfo [ 'pid' ] , path [ 0 : - 10 ] ) if val not in deleted_files : deleted_files . append ( val ) yield val try : for link in listdir : path = dirpath + link readlink = os . readlink ( path ) filenames = [ ] if os . path . isfile ( readlink ) : filenames . append ( readlink ) elif os . path . isdir ( readlink ) and readlink != '/' : for root , dummy_dirs , files in salt . utils . path . os_walk ( readlink , followlinks = True ) : for name in files : filenames . append ( os . path . join ( root , name ) ) for filename in filenames : valid = _valid_deleted_file ( filename ) if not valid : continue val = ( pinfo [ 'name' ] , pinfo [ 'pid' ] , filename ) if val not in deleted_files : deleted_files . append ( val ) yield val except OSError : pass except psutil . NoSuchProcess : pass
Iterates over /proc/PID/maps and /proc/PID/fd links and returns list of desired deleted files.

    Returns:
        List of deleted files to analyze, False on failure.