2019-08-10 23:57:26 +08:00
|
|
|
#!/usr/bin/env bash
|
2008-01-09 06:11:00 +08:00
|
|
|
############################################################################
|
2012-12-09 00:37:43 +08:00
|
|
|
# tools/copydir.sh
|
2008-01-09 06:11:00 +08:00
|
|
|
#
|
2021-02-18 20:48:10 +08:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership. The
|
|
|
|
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance with the
|
|
|
|
# License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2008-01-09 06:11:00 +08:00
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
#
|
|
|
|
# NuttX uses symbolic links to configure platform-specific directories into
|
|
|
|
# the build system. This works great except for when a Windows native
|
|
|
|
# toolchain is used in a Cygwin environment. In that case, symbolic
|
|
|
|
# links do not work correctly when accessed from the Windows native toolchain;
|
|
|
|
# rather, just look link files with the extension .lnk
|
|
|
|
#
|
|
|
|
# In this environment, the build system will work around this using this script
|
|
|
|
# as a replacement for the 'ln' command. This scrpt will simply copy the
|
|
|
|
# directory into the expected positiion.
|
|
|
|
#
|
2008-01-09 08:07:03 +08:00
|
|
|
#set -x
|
2008-01-09 06:11:00 +08:00
|
|
|
|
|
|
|
src=$1
|
|
|
|
dest=$2
|
|
|
|
|
|
|
|
# Verify that arguments were provided
|
|
|
|
|
|
|
|
if [ -z "${src}" -o -z "${dest}" ]; then
|
2020-01-06 00:29:59 +08:00
|
|
|
echo "Missing src and/or dest arguments"
|
|
|
|
exit 1
|
2008-01-09 06:11:00 +08:00
|
|
|
fi
|
|
|
|
|
2008-01-09 07:55:02 +08:00
|
|
|
# Check if something already exists at the destination path replace it with
|
|
|
|
# the new link (which might be different). Note that we check for the
|
|
|
|
# the link (-h) before we check for existence (-e) because a bad link will
|
|
|
|
# report that it does not exist.
|
2008-01-09 06:11:00 +08:00
|
|
|
|
2008-01-09 07:55:02 +08:00
|
|
|
if [ -h "${dest}" ]; then
|
2020-01-06 00:29:59 +08:00
|
|
|
rm -f "${dest}"
|
2008-01-09 07:55:02 +08:00
|
|
|
else
|
2008-01-09 06:11:00 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
# If the path exists and is a directory that contains the "fake link"
|
|
|
|
# mark, then treat it like a soft link (i.e., remove the directory)
|
2008-01-09 06:11:00 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
if [ -d "${dest}" -a -f "${dest}/.fakelnk" ]; then
|
|
|
|
rm -rf "${dest}"
|
|
|
|
else
|
2008-01-09 06:11:00 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
# Does anything exist at the destination path?
|
2008-01-09 06:11:00 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
if [ -e "${dest}" ]; then
|
2008-01-09 06:11:00 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
# It is something else (like a file) or directory that does
|
|
|
|
# not contain the "fake link" mark
|
2008-01-09 06:11:00 +08:00
|
|
|
|
2020-01-06 00:29:59 +08:00
|
|
|
echo "${dest} already exists but is not a symbolic link"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2008-01-09 06:11:00 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Verify that a directory exists at the source path
|
|
|
|
|
2008-01-09 07:55:02 +08:00
|
|
|
if [ ! -d "${src}" ]; then
|
2020-01-06 00:29:59 +08:00
|
|
|
echo "No directory at ${src}"
|
|
|
|
exit 1
|
2008-01-09 06:11:00 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Copy the directory
|
|
|
|
|
|
|
|
cp -a "${src}" "${dest}" || \
|
2020-01-06 00:29:59 +08:00
|
|
|
{ echo "Failed to create link: $dest" ; rm -rf ${dest} ; exit 1 ; }
|
2008-01-09 06:11:00 +08:00
|
|
|
touch "${dest}/.fakelnk" || \
|
2020-01-06 00:29:59 +08:00
|
|
|
{ echo "Failed to touch ${dest}/.fakelnk" ; rm -rf ${dest} ; exit 1 ; }
|