logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

mkdir.sh (2354B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. WD="$(dirname "$0")"
  5. target="${WD}/../cmd/mkdir"
  6. target_chmod="${WD}/../cmd/chmod"
  7. plans=15
  8. . "${WD}/tap.sh"
  9. t --exit=1 noargs '' 'mkdir: error: Missing operand
  10. Usage: mkdir [-pv] [-m mode] path ...
  11. '
  12. umask 002
  13. t_cmd foo:absent '' rm -f foo
  14. t foo:mkdir foo
  15. t_cmd foo:isdir '' test -d foo
  16. t_cmd foo:rm '' rm -r foo
  17. t_cmd enoent:absent '' test ! -e enoent
  18. t --exit=1 foo:mkdir enoent/file "mkdir: error: Failed making directory 'enoent/file': No such file or directory
  19. "
  20. t_cmd enoent:still_absent '' test ! -e enoent
  21. t_mkdir_parents() {
  22. t_err=0
  23. test ! -e gaia || return 1
  24. "${target}" -p gaia/zeus || t_err=1
  25. "${target_chmod}" -v + gaia gaia/zeus || t_err=1
  26. rm -r gaia || t_err=1
  27. return $t_err
  28. }
  29. t_cmd mkdir_parents "chmod: Permissions already set to 00775/drwxrwxr-x for 'gaia'
  30. chmod: Permissions already set to 00775/drwxrwxr-x for 'gaia/zeus'
  31. " t_mkdir_parents
  32. t_mkdir_v() {
  33. t_err=0
  34. for dir; do
  35. test ! -e "$dir" || return 1
  36. done
  37. "${target}" -v "$@" || return 1
  38. for dir; do
  39. test -d "$dir" || t_err=1
  40. done
  41. rm -r "$@" || t_err=1
  42. return $t_err
  43. }
  44. t_cmd verbose "mkdir: Made directory: verbose1
  45. mkdir: Made directory: verbose2
  46. " t_mkdir_v verbose1 verbose2
  47. t_cmd --exit=1 verbose_no_parents "mkdir: error: Failed making directory 'verbose_foo/verbose_bar': No such file or directory
  48. " t_mkdir_v verbose_foo/verbose_bar
  49. t_mkdir_mode() {
  50. t_err=0
  51. test ! -e "$2" || return 1
  52. "${target}" -m "$1" "$2" || t_err=1
  53. "${target_chmod}" -v + "$2" || t_err=1
  54. rm -r "$2" || t_err=1
  55. return $t_err
  56. }
  57. t_cmd plus_x "chmod: Permissions already set to 00775/drwxrwxr-x for 'plus_x'
  58. " t_mkdir_mode +x plus_x
  59. t_cmd go_minus_x "chmod: Permissions already set to 00764/drwxrw-r-- for 'go_minus_x'
  60. " t_mkdir_mode go-x go_minus_x
  61. t_cmd minus_x "chmod: Permissions already set to 00664/drw-rw-r-- for 'minus_x'
  62. " t_mkdir_mode -x minus_x
  63. t_mkdir_024() {
  64. t_err=0
  65. umask 024
  66. test ! -e zero_two || return 1
  67. "${target}" -p zero_two/four || t_err=1
  68. "${target_chmod}" -v + zero_two zero_two/four || t_err=1
  69. rm -r zero_two || t_err=1
  70. return $t_err
  71. }
  72. t_cmd 024 "chmod: Permissions already set to 00753/drwxr-x-wx for 'zero_two'
  73. chmod: Permissions already set to 00753/drwxr-x-wx for 'zero_two/four'
  74. " t_mkdir_024