link.bat 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. @echo off
  2. rem tools/link.bat
  3. rem
  4. rem Licensed to the Apache Software Foundation (ASF) under one or more
  5. rem contributor license agreements. See the NOTICE file distributed with
  6. rem this work for additional information regarding copyright ownership. The
  7. rem ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. rem "License"); you may not use this file except in compliance with the
  9. rem License. You may obtain a copy of the License at
  10. rem
  11. rem http://www.apache.org/licenses/LICENSE-2.0
  12. rem
  13. rem Unless required by applicable law or agreed to in writing, software
  14. rem distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. rem WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. rem License for the specific language governing permissions and limitations
  17. rem under the License.
  18. rem
  19. set usemklink=
  20. if "%1"=="-m" (
  21. set usemklink="y"
  22. shift
  23. )
  24. set src=%1
  25. set link=%2
  26. rem Verify that arguments were provided
  27. if "%src%"=="" goto :MissingSrc
  28. if "%link%"=="" goto :MissingLink
  29. goto CheckSrc
  30. :MissingSrc
  31. echo Missing ^<src^> and ^<link^> arguments
  32. goto :ShowUsage
  33. :MissingLink
  34. echo Missing ^<link^> arguments
  35. goto :ShowUsage
  36. rem Verify that a directory exists at the source path
  37. :CheckSrc
  38. if exist %src% goto :CheckLink
  39. echo No directory at %src%
  40. goto :ShowUsage
  41. :CheckLink
  42. rem If something already exists at the destination path, remove it
  43. if not exist %link% goto :MkLink
  44. rmdir /q /s %link%
  45. if errorlevel 1 (
  46. echo Failed to remove existing object at %link%
  47. goto :ShowUsage
  48. )
  49. rem Copy the directory
  50. :MkLink
  51. if "%usemklink%"=="y" (
  52. /user:administrator mklink /d %src% %link%
  53. goto :End
  54. )
  55. rem %src% may include forward slashes. That upsets xcopy, but not GNUWin32 cp
  56. rem xcopy %src% %link% /c /q /s /e /y /i
  57. cp -dR %src% %link%
  58. echo FAKELNK > %link%\.fakelnk
  59. goto :End
  60. :ShowUsage
  61. echo USAGE: %0 ^<src^> ^<link^>
  62. echo Where:
  63. echo ^<src^> is the source directory to be linked
  64. echo ^<link^> is the link to be created
  65. :End