3 # Copyright (C) 2016 The Android Open Source Project
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # create files with 644 (global read) permissions.
20 # Helper function to copy files
24 # Move to a temporary file so we can do a rename and have the preopted file
25 # appear atomically in the filesystem.
26 temp_dest_name=${dest_name}.tmp
27 if ! cp ${odex_file} ${temp_dest_name} ; then
28 log -p w -t cppreopts "Unable to copy odex file ${odex_file} to ${temp_dest_name}!"
30 log -p i -t cppreopts "Copied odex file from ${odex_file} to ${temp_dest_name}"
32 if ! mv ${temp_dest_name} ${dest_name} ; then
33 log -p w -t cppreopts "Unable to rename temporary odex file from ${temp_dest_name} to ${dest_name}"
35 log -p i -t cppreopts "Renamed temporary odex file from ${temp_dest_name} to ${dest_name}"
41 # Where the system_b is mounted that contains the preopt'd files
44 if ! test -f ${mountpoint}/system-other-odex-marker ; then
45 log -p i -t cppreopts "system_other partition does not appear have been built to contain preopted files."
49 log -p i -t cppreopts "cppreopts from ${mountpoint}"
50 # For each odex file do the copy task
51 # NOTE: this implementation will break in any path with spaces to favor
52 # background copy tasks
53 for odex_file in $(find ${mountpoint} -type f -name "*.odex"); do
54 real_odex_name=${odex_file/${mountpoint}/\/system}
55 dest_name=$(preopt2cachename ${real_odex_name})
56 if ! test $? -eq 0 ; then
57 log -p i -t cppreopts "Unable to figure out destination for ${odex_file}"
60 # Copy files in background to speed things up
61 do_copy ${odex_file} ${dest_name} &
63 # Wait for jobs to finish
67 log -p e -t cppreopts "Usage: cppreopts <preopts-mount-point>"