OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.8 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-cleanup-linger
  6. # Copyright (C) 2006 - 2013 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. #Description: Removes temp files and search for lingering files
  18. #Alias: lingering
  19. [ -n "$SDEROOT" ] ||
  20. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  21. . $SDEROOT/lib/libsde.in
  22. cleanup_usage() {
  23. local progname="${0##*/}"
  24. cat <<EOT
  25. Usage: $progname [--dry-run]
  26. EOT
  27. }
  28. shortopts='d'
  29. longopts='dry-run'
  30. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  31. if [ $? -ne 0 ]; then
  32. cleanup_usage
  33. exit -1
  34. fi
  35. # load new arguments list
  36. eval set -- "$options"
  37. dryrun=
  38. while [ $# -gt 0 ]; do
  39. case "$1" in
  40. --) shift; break ;;
  41. -d|--dry-run)
  42. dryrun=yes ;;
  43. esac
  44. shift
  45. done
  46. cd "$SDEROOT"
  47. echo_info "Searching for lingering temp/backup files (this may take some time) ..."
  48. sderootdirs="scripts/. bin/. etc/. lib/. doc/. src/. package/. architecture/." # target/.
  49. files_remove="-name *~ -o -name a.out -o -name core.[0-9]* -o -name core"
  50. files_warn="-name DEADJOE -o -name *-[xX] \
  51. -o -name *.orig -o -name *.rej -o -name *#* \
  52. -o -name *.mine -o -name *.r[1-9][0-9]* \
  53. -o -name TRANS.TBL -o -name *.cksum-err -o -name x \
  54. -o -name *[.-]old -o -name a.out -o -name *~ \
  55. -o -name *.incomplete -o -name *.ckext-err"
  56. # Remove temp/backup files
  57. #
  58. remove() {
  59. if [ "x-d" = "x${1:-}" ]; then
  60. shift
  61. bin/find $sderootdirs target/. -type f \( "$@" \)
  62. else
  63. bin/find $sderootdirs target/. -type f \( "$@" \) -print0 | xargs -r0 rm -vf
  64. fi
  65. }
  66. remove ${dry_run:+-d} $files_remove
  67. # Print warnings for 'lingering' files
  68. #
  69. ( bin/find ${sderootdirs} \( \
  70. \( \( $files_warn -o -name '.[^.]*' \) \
  71. -a ! -name '.gitignore' -a ! -name '.gitattributes' \) \
  72. -printf 'WARNING: Found %p\n' \
  73. \) -o \( \
  74. \( ! -type d ! -type f \) \
  75. -printf 'WARNING: Neither a dir nor a regular file: %p\n' \
  76. \) ) &
  77. # for targets we tolerate .files
  78. ( bin/find target/. \( \
  79. \( $files_warn \) \
  80. -printf 'WARNING: Found %p\n' \
  81. \) -o \( \
  82. \( ! -type d ! -type f \) \
  83. -printf 'WARNING: Neither a dir nor a regular file: %p\n' \
  84. \) ) &
  85. wait
  86. exit 0