Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- bugfix TARGETGROUP_DEL_TARGET : work with a temp file

- optimize : make operation only if necesssary
  • Loading branch information...
commit cb168616d39b333011f0396c88a10d6a129d71cf 1 parent 947db8d
@Tauop authored
Showing with 22 additions and 18 deletions.
  1. +22 −18 bin/core/targetgroup.func
View
40 bin/core/targetgroup.func
@@ -145,7 +145,7 @@ if [ "${__TARGETGROUP_FUNC__:-}" != 'Loaded' ]; then
# usage: TARGETGROUP_DEL_TARGET <target_group> [<login>@]<target>
# desc: Remove an target from a group
TARGETGROUP_DEL_TARGET () {
- local targetgroup= target= login= target_real= item= pattern= file= tmpfile=
+ local targetgroup= target= login= target_real= item= pattern= file= tmp_file=
if [ $# -ne 2 ]; then
BAD_ARGUMENTS ; return 1;
fi
@@ -159,28 +159,32 @@ if [ "${__TARGETGROUP_FUNC__:-}" != 'Loaded' ]; then
fi
file="${SSHGATE_DIR_TARGETS_GROUPS}/${targetgroup}/${SSHGATE_TARGETS_GROUPS_TARGETS_FILENAME}"
+ if [ -f "${file}" ]; then
+ if [ "${target}" != "${target%%@*}" ]; then
+ login="${target%%@*}";
+ TARGET_SSH_LIST_LOGINS "${target_real}" | grep "^${login}$" >/dev/null
+ if [ $? -ne 0 ]; then
+ ERROR "Login '${login}' doesn't exist on target '${target_real}'"; return 1;
+ fi
+ item="${login}@${target_real}"
+ pattern="${item}"
+ else
+ item="${target_real}"
+ pattern="(${target_real}|[^@]*@${target_real})"
+ fi
- if [ "${target}" != "${target%%@*}" ]; then
- login="${target%%@*}";
- TARGET_SSH_LIST_LOGINS "${target_real}" | grep "^${login}$" >/dev/null
- if [ $? -ne 0 ]; then
- ERROR "Login '${login}' doesn't exist on target '${target_real}'"; return 1;
+ # remove target from targetgroup
+ tmp_file="/tmp/file.$(RANDOM)"
+ cat "${file}" | grep -v -E "^${pattern}\$" > "${tmp_file}"
+ if [ ! -s "${tmp_file}" ]; then
+ rm -f "${file}" "${tmp_file}"
+ else
+ mv "${tmp_file}" "${file}"
fi
- item="${login}@${target_real}"
- pattern="${item}"
- else
- item="${target_real}"
- pattern="(${target_real}|[^@]*@${target_real})"
- fi
- # remove target from targetgroup
- TARGETGROUP_LIST_TARGETS "${targetgroup}" | grep -v -E "^${pattern}\$" > "${file}"
- if [ ! -s "${tmp_file}" ]; then
- rm -f "${file}"
+ private_MAIL_APPEND "Target ${item} removed from User Group ${targetgroup}"
fi
- private_MAIL_APPEND "Target ${item} removed from User Group ${targetgroup}"
-
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.