def find_files_in_layers(img, files, tmpdir=None):
import tempfile<EOL>import json<EOL>client = get_client()<EOL>result = {f: [] for f in files}<EOL>if tmpdir is None:<EOL><INDENT>tmpdir = tempfile.mkdtemp()<EOL><DEDENT>img = client.images.get(img)<EOL>tarpath = os.path.join(tmpdir, '<STR_LIT>')<EOL>with open(tarpath, '<STR_LIT:wb>') as tf:<EOL><INDENT>for chunk in img.save():<EOL><INDENT>tf.write(chunk)<EOL><DEDENT><DEDENT>with tarfile.open(tarpath, '<STR_LIT:r>') as tf:<EOL><INDENT>mf_obj = tf.extractfile('<STR_LIT>')<EOL>manifest = json.loads(mf_obj.read().decode('<STR_LIT:utf-8>'))<EOL>assert len(manifest) == <NUM_LIT:1><EOL>for path_to_layer_tar in manifest[<NUM_LIT:0>]['<STR_LIT>']:<EOL><INDENT>layer_tar_buffer = tf.extractfile(path_to_layer_tar)<EOL>with tarfile.open('<STR_LIT:r>', fileobj=layer_tar_buffer) as layertar:<EOL><INDENT>layer_results = _scan_tar(layertar, files)<EOL>for f in layer_results:<EOL><INDENT>result[f].append(path_to_layer_tar[:-len('<STR_LIT>')])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return result<EOL>
Scans an image's layers looking for specific files.

    There's no API for this, so it's brittle. We're looking at
    every layer stored internally for a given image. The solution here just uses `docker save`
    to dump the layers to disk and examine them. This was written to parse the format of the
    tarfile from docker 18.03.1; I'm not sure how stable this is, either backwards or forwards.

    Note that this is used for TESTING ONLY, it's not part of the actual code (right now)

    Args:
        img (str): image id or name
        files (List[str]): list of paths to look for
        tmpdir (str): temporary directory to save

    Returns:
        dict[str, List[str]]: Dict storing the layers each file is present in