• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2023 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import argparse
17import os
18import subprocess
19import sys
20import shutil
21
22
23def copy_file(src_dir, dest_dir):
24    src_name = '/cupsfilters.convs.in'
25    dest_name = '/cupsfilters.convs'
26    src_file = src_dir + src_name
27    dest_file = dest_dir + dest_name
28    shutil.copy2(src_file, dest_file)
29
30
31def apply_patch(patch_file, target_dir):
32    try:
33        if not os.path.exists(target_dir):
34            return
35        patch_cmd = ['patch', '-p1', "--fuzz=0", "--no-backup-if-mismatch", '-i', patch_file, '-d', target_dir]
36        subprocess.run(patch_cmd, check=True)
37    except Exception as e:
38        print("apply_patch error!")
39        return
40
41
42def do_patch(target_dir):
43    patch_file = [
44        "ohos_pdftoraster.patch",
45        "ohos_ghostscript.patch",
46        "backport-CVE-2023-24805.patch",
47    ]
48
49    for patch in patch_file:
50        apply_patch(patch, target_dir)
51
52
53def main():
54    path = argparse.ArgumentParser()
55    path.add_argument('--gen-dir', help='generate path of log', required=True)
56    path.add_argument('--source-dir', help='generate path of log', required=True)
57    args = path.parse_args()
58    convs_dir = os.path.join(args.source_dir, "mime")
59
60    do_patch(args.source_dir)
61    copy_file(convs_dir, args.gen_dir)
62    return 0
63
64if __name__ == '__main__':
65    sys.exit(main())
66