Пример #1
0
def apply_patch_temporarily(workdir, patch, files=None):
    patch_file = patch_file_name(patch)
    args = patch_args(patch)
    srcdir = os.path.join(QUILT_PC, patch)
    if not backup.restore(srcdir, to_dir=workdir, filelist=files, keep=True):
        output.error('Failed to copy files to temporary directory\n')
        return False
    if os.path.isfile(patch_file) and os.path.getsize(patch_file) > 0:
        text = fsutils.get_file_contents(patch_file)
        result = putils.apply_patch(indir=workdir, patch_args=' '.join(args) + ' --no-backup-if-mismatch -Ef', patch_file=patch_file)
        if result.eflags != 0:
            # Generating a relative diff for a subset of files in
            # the patch will fail. Also, if a patch was force
            # applied, we know that it won't apply cleanly. In
            # all other cases, print a warning.
            if not os.path.isfile(os.path.join(QUILT_PC, patch + '~refresh')) and len(files) == 0:
                output.error('Failed to patch temporary files\n')
                return False
    return True
Пример #2
0
def check_for_pending_changes(patch):
    patch_file = patchfns.patch_file_name(patch)
    workdir = patchfns.gen_tempfile(template='quilt', asdir=True)
    patchdir = os.path.join(patchfns.QUILT_PC, patch)
    if os.path.isdir(patchdir):
        prefix = os.path.abspath(patchdir)
        if not backup.restore(prefix, to_dir=workdir, keep=True):
            output.error('Failed to copy files to temporary directory\n')
            shutil.rmtree(workdir)
            return False
    if os.path.exists(patch_file) and os.path.getsize(patch_file) > 0:
        patch_args = '%s --no-backup-if-mismatch -E' % ' '.join(patchfns.patch_args(patch))
        result = putils.apply_patch(patch_file, indir=workdir, patch_args=patch_args)
        if result.eflags != 0 and not os.path.exists(patchdir):
            output.write(result.stdout)
            output.error('Failed to patch temporary files\n')
            shutil.rmtree(workdir)
            return False
    failed = False
    for file_nm in patchfns.files_in_patch(patch):
        wfile_nm = os.path.join(workdir, file_nm)
        if not os.path.exists(file_nm):
            if os.path.exists(wfile_nm):
                failed = True
                break
            else:
                continue
        elif not os.path.exists(wfile_nm):
            failed = True
            break
        if not diff.same_contents(file_nm, wfile_nm):
            failed = True
            break
    shutil.rmtree(workdir)
    if failed:
        output.error('Patch %s does not remove cleanly (refresh it or enforce with -f)\n' % patchfns.print_patch(patch))
        return cmd_result.ERROR_SUGGEST_FORCE
    return True
Пример #3
0
 def apply_patch(patch_file, patch_args):
     if not os.path.exists(patch_file) or os.path.getsize(patch_file) == 0:
         return cmd_result.Result(0, '', '')
     return putils.apply_patch(patch_file, patch_args=patch_args)