OSDN Git Service

Copy preopted files from B partition.
[android-x86/system-extras.git] / cppreopts / cppreopts.sh
1 #!/system/bin/sh
2 #
3 # Copyright (C) 2016 The Android Open Source Project
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # create files with 644 (global read) permissions.
18 umask 022
19
20 if [ $# -ne 1 ]; then
21   log -p e -t cppreopts "Usage: cppreopts <preopts-mount-point>"
22   exit 1
23 fi
24
25 # Where the system_b is mounted that contains the preopt'd files
26 mountpoint=$1
27
28 if ! test -f ${mountpoint}/system-other-odex-marker ; then
29   log -p i -t cppreopts "system_other partition does not appear have been built to contain preopted files."
30   exit 1
31 fi
32
33 log -p i -t cppreopts "cppreopts from ${mountpoint}"
34 # For each odex file.
35 find ${mountpoint} -type f -name "*.odex" | while read odex_file; do
36   real_odex_name=${odex_file/${mountpoint}/\/system}
37   dest_name=$(preopt2cachename ${real_odex_name})
38   # Move to a temporary file so we can do a rename and have the preopted file
39   # appear atomically in the filesystem.
40   temp_dest_name=${dest_name}.tmp
41   if ! test $? -eq 0 ; then
42     log -p i -t cppreopts "Unable to figure out destination for ${odex_file}"
43     continue
44   fi
45   if ! cp ${odex_file} ${temp_dest_name} ; then
46     log -p w -t cppreopts "Unable to copy odex file ${odex_file} to ${temp_dest_name}!"
47   else
48     log -p i -t cppreopts "Copied odex file from ${odex_file} to ${temp_dest_name}"
49     sync
50     if ! mv ${temp_dest_name} ${dest_name} ; then
51       log -p w -t cppreopts "Unable to rename temporary odex file from ${temp_dest_name} to ${dest_name}"
52     else
53       log -p i -t cppreopts "Renamed temporary odex file from ${temp_dest_name} to ${dest_name}"
54     fi
55   fi
56 done
57
58 exit 0