'Check for leftover files from partially-completed prior install to
prepare for a new install attempt. Options control whether these
files are reused (vs. destroyed). This function considers a package
fully-installed if there is a DB entry for it (in that way, it is
more strict than Package.installed). The return value is used to
indicate when the prefix exists but the install is not complete.'

def check_for_unfinished_installation(self, keep_prefix=False, restage=False):

    if self.spec.external:
        raise ExternalPackageError(('Attempted    to    repair    external    spec    %s' % self.spec.name))
    with spack.store.db.prefix_write_lock(self.spec):
        try:
            record = spack.store.db.get_record(self.spec)
            installed_in_db = (record.installed if record else False)
        except KeyError:
            installed_in_db = False
        partial = False
        if ((not installed_in_db) and os.path.isdir(self.prefix)):
            if (not keep_prefix):
                self.remove_prefix()
            else:
                partial = True
    stage_is_managed_in_spack = self.stage.path.startswith(spack.stage_path)
    if (restage and stage_is_managed_in_spack):
        self.stage.destroy()
        self.stage.create()
    return partial
