copydir.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. ############################################################################
  3. # tools/copydir.sh
  4. #
  5. # Licensed to the Apache Software Foundation (ASF) under one or more
  6. # contributor license agreements. See the NOTICE file distributed with
  7. # this work for additional information regarding copyright ownership. The
  8. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  9. # "License"); you may not use this file except in compliance with the
  10. # License. You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  17. # License for the specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. ############################################################################
  21. #
  22. # NuttX uses symbolic links to configure platform-specific directories into
  23. # the build system. This works great except for when a Windows native
  24. # toolchain is used in a Cygwin environment. In that case, symbolic
  25. # links do not work correctly when accessed from the Windows native toolchain;
  26. # rather, just look link files with the extension .lnk
  27. #
  28. # In this environment, the build system will work around this using this script
  29. # as a replacement for the 'ln' command. This scrpt will simply copy the
  30. # directory into the expected positiion.
  31. #
  32. #set -x
  33. src=$1
  34. dest=$2
  35. # Verify that arguments were provided
  36. if [ -z "${src}" -o -z "${dest}" ]; then
  37. echo "Missing src and/or dest arguments"
  38. exit 1
  39. fi
  40. # Check if something already exists at the destination path replace it with
  41. # the new link (which might be different). Note that we check for the
  42. # the link (-h) before we check for existence (-e) because a bad link will
  43. # report that it does not exist.
  44. if [ -h "${dest}" ]; then
  45. rm -f "${dest}"
  46. else
  47. # If the path exists and is a directory that contains the "fake link"
  48. # mark, then treat it like a soft link (i.e., remove the directory)
  49. if [ -d "${dest}" -a -f "${dest}/.fakelnk" ]; then
  50. rm -rf "${dest}"
  51. else
  52. # Does anything exist at the destination path?
  53. if [ -e "${dest}" ]; then
  54. # It is something else (like a file) or directory that does
  55. # not contain the "fake link" mark
  56. echo "${dest} already exists but is not a symbolic link"
  57. exit 1
  58. fi
  59. fi
  60. fi
  61. # Verify that a directory exists at the source path
  62. if [ ! -d "${src}" ]; then
  63. echo "No directory at ${src}"
  64. exit 1
  65. fi
  66. # Copy the directory
  67. cp -a "${src}" "${dest}" || \
  68. { echo "Failed to create link: $dest" ; rm -rf ${dest} ; exit 1 ; }
  69. touch "${dest}/.fakelnk" || \
  70. { echo "Failed to touch ${dest}/.fakelnk" ; rm -rf ${dest} ; exit 1 ; }