Skip to content

Commit

Permalink
Use grep for -ex and -in flag | Resolve labbots#176
Browse files Browse the repository at this point in the history
  • Loading branch information
Akianonymus committed May 15, 2022
1 parent 16ee31b commit 334ecea
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
18 changes: 11 additions & 7 deletions release/bash/gupload
Original file line number Diff line number Diff line change
Expand Up @@ -583,25 +583,25 @@ fi
EOF
_parser_setup_flag "-in --include" 1 required "pattern"
_parser_setup_flag_help \
"Only include the files with the given pattern to upload - Applicable for folder uploads.
"Only upload the files which contains the given pattern - Applicable for folder uploads.
e.g: ${0##*/} local_folder --include '*1*', will only include with files with pattern '1' in the name."
e.g: ${0##*/} local_folder --include 1, will only include with files with pattern 1 in the name. Regex can be used which works with grep -E command."
_parser_setup_flag_preprocess 4<<'EOF'
unset INCLUDE_FILES
EOF
_parser_setup_flag_process 4<<'EOF'
INCLUDE_FILES="${INCLUDE_FILES} -name '${2}' " && _parser_shift
export INCLUDE_FILES="${INCLUDE_FILES:+${INCLUDE_FILES}|}${2}" && _parser_shift
EOF
_parser_setup_flag "-ex --exclude" 1 required "pattern"
_parser_setup_flag_help \
"Exclude the files with the given pattern from uploading. - Applicable for folder uploads.
"Only download the files which does not contain the given pattern - Applicable for folder downloads.
e.g: ${0##*/} local_folder --exclude "*1*", will exclude all the files pattern '1' in the name."
e.g: ${0##*/} local_folder --exclude 1, will only include with files with pattern 1 not present in the name. Regex can be used which works with grep -E command."
_parser_setup_flag_preprocess 4<<'EOF'
unset EXCLUDE_FILES
EOF
_parser_setup_flag_process 4<<'EOF'
EXCLUDE_FILES="${EXCLUDE_FILES} -name ! '${2}' " && _parser_shift
export EXCLUDE_FILES="${EXCLUDE_FILES:+${EXCLUDE_FILES}|}${2}" && _parser_shift
EOF
_parser_setup_flag "--hide" 0
_parser_setup_flag_help \
Expand Down Expand Up @@ -1798,11 +1798,15 @@ NEXTROOTDIRID="$WORKSPACE_FOLDER_ID"
"$EXTRA_LOG" "justify" "Processing folder.." "-"
[ -z "$SKIP_SUBDIRS" ]&&"$EXTRA_LOG" "justify" "Indexing subfolders.." "-"
DIRNAMES="$(find "$input" -type d -not -empty)"
[ -n "$INCLUDE_FILES" ]&&_tmp_dirnames="$(printf "%s\n" "$DIRNAMES"|grep -E "$INCLUDE_FILES")"&&DIRNAMES="$_tmp_dirnames"
[ -n "$EXCLUDE_FILES" ]&&_tmp_dirnames="$(printf "%s\n" "$DIRNAMES"|grep -Ev "$INCLUDE_FILES")"&&DIRNAMES="$_tmp_dirnames"
NO_OF_FOLDERS="$(($(printf "%s\n" "$DIRNAMES"|wc -l)))"&&NO_OF_SUB_FOLDERS="$((NO_OF_FOLDERS-1))"
[ -z "$SKIP_SUBDIRS" ]&&_clear_line 1
[ "$NO_OF_SUB_FOLDERS" = 0 ]&&SKIP_SUBDIRS="true"
"$EXTRA_LOG" "justify" "Indexing files.." "-"
FILENAMES="$(_tmp='find "'$input'" -type f -name "*" '$INCLUDE_FILES' '$EXCLUDE_FILES''&&eval "$_tmp")"
FILENAMES="$(find "$input" -type f)"
[ -n "$INCLUDE_FILES" ]&&_tmp_filenames="$(printf "%s\n" "$FILENAMES"|grep -E "$EXCLUDE_FILES")"&&FILENAMES="$_tmp_filenames"
[ -n "$EXCLUDE_FILES" ]&&_tmp_filenames="$(printf "%s\n" "$FILENAMES"|grep -Ev "$EXCLUDE_FILES")"&&FILENAMES="$_tmp_filenames"
_clear_line 1
if [ -n "$SKIP_SUBDIRS" ];then
if [ -n "$FILENAMES" ];then
Expand Down
18 changes: 11 additions & 7 deletions release/sh/gupload
Original file line number Diff line number Diff line change
Expand Up @@ -556,25 +556,25 @@ fi
EOF
_parser_setup_flag "-in --include" 1 required "pattern"
_parser_setup_flag_help \
"Only include the files with the given pattern to upload - Applicable for folder uploads.
"Only upload the files which contains the given pattern - Applicable for folder uploads.
e.g: ${0##*/} local_folder --include '*1*', will only include with files with pattern '1' in the name."
e.g: ${0##*/} local_folder --include 1, will only include with files with pattern 1 in the name. Regex can be used which works with grep -E command."
_parser_setup_flag_preprocess 4<<'EOF'
unset INCLUDE_FILES
EOF
_parser_setup_flag_process 4<<'EOF'
INCLUDE_FILES="${INCLUDE_FILES} -name '${2}' " && _parser_shift
export INCLUDE_FILES="${INCLUDE_FILES:+${INCLUDE_FILES}|}${2}" && _parser_shift
EOF
_parser_setup_flag "-ex --exclude" 1 required "pattern"
_parser_setup_flag_help \
"Exclude the files with the given pattern from uploading. - Applicable for folder uploads.
"Only download the files which does not contain the given pattern - Applicable for folder downloads.
e.g: ${0##*/} local_folder --exclude "*1*", will exclude all the files pattern '1' in the name."
e.g: ${0##*/} local_folder --exclude 1, will only include with files with pattern 1 not present in the name. Regex can be used which works with grep -E command."
_parser_setup_flag_preprocess 4<<'EOF'
unset EXCLUDE_FILES
EOF
_parser_setup_flag_process 4<<'EOF'
EXCLUDE_FILES="${EXCLUDE_FILES} -name ! '${2}' " && _parser_shift
export EXCLUDE_FILES="${EXCLUDE_FILES:+${EXCLUDE_FILES}|}${2}" && _parser_shift
EOF
_parser_setup_flag "--hide" 0
_parser_setup_flag_help \
Expand Down Expand Up @@ -1767,11 +1767,15 @@ NEXTROOTDIRID="$WORKSPACE_FOLDER_ID"
"$EXTRA_LOG" "justify" "Processing folder.." "-"
[ -z "$SKIP_SUBDIRS" ]&&"$EXTRA_LOG" "justify" "Indexing subfolders.." "-"
DIRNAMES="$(find "$input" -type d -not -empty)"
[ -n "$INCLUDE_FILES" ]&&_tmp_dirnames="$(printf "%s\n" "$DIRNAMES"|grep -E "$INCLUDE_FILES")"&&DIRNAMES="$_tmp_dirnames"
[ -n "$EXCLUDE_FILES" ]&&_tmp_dirnames="$(printf "%s\n" "$DIRNAMES"|grep -Ev "$INCLUDE_FILES")"&&DIRNAMES="$_tmp_dirnames"
NO_OF_FOLDERS="$(($(printf "%s\n" "$DIRNAMES"|wc -l)))"&&NO_OF_SUB_FOLDERS="$((NO_OF_FOLDERS-1))"
[ -z "$SKIP_SUBDIRS" ]&&_clear_line 1
[ "$NO_OF_SUB_FOLDERS" = 0 ]&&SKIP_SUBDIRS="true"
"$EXTRA_LOG" "justify" "Indexing files.." "-"
FILENAMES="$(_tmp='find "'$input'" -type f -name "*" '$INCLUDE_FILES' '$EXCLUDE_FILES''&&eval "$_tmp")"
FILENAMES="$(find "$input" -type f)"
[ -n "$INCLUDE_FILES" ]&&_tmp_filenames="$(printf "%s\n" "$FILENAMES"|grep -E "$EXCLUDE_FILES")"&&FILENAMES="$_tmp_filenames"
[ -n "$EXCLUDE_FILES" ]&&_tmp_filenames="$(printf "%s\n" "$FILENAMES"|grep -Ev "$EXCLUDE_FILES")"&&FILENAMES="$_tmp_filenames"
_clear_line 1
if [ -n "$SKIP_SUBDIRS" ];then
if [ -n "$FILENAMES" ];then
Expand Down
16 changes: 15 additions & 1 deletion src/common/upload-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,26 @@ _process_arguments() {
[ -z "${SKIP_SUBDIRS}" ] && "${EXTRA_LOG}" "justify" "Indexing subfolders.." "-"
# Do not create empty folders during a recursive upload. Use of find in this section is important.
DIRNAMES="$(find "${input}" -type d -not -empty)"

# include or exlude the files if -in or -ex flag was used, use grep
[ -n "${INCLUDE_FILES}" ] && _tmp_dirnames="$(printf "%s\n" "${DIRNAMES}" | grep -E "${INCLUDE_FILES}")" &&
DIRNAMES="${_tmp_dirnames}"
[ -n "${EXCLUDE_FILES}" ] && _tmp_dirnames="$(printf "%s\n" "${DIRNAMES}" | grep -Ev "${INCLUDE_FILES}")" &&
DIRNAMES="${_tmp_dirnames}"

NO_OF_FOLDERS="$(($(printf "%s\n" "${DIRNAMES}" | wc -l)))" && NO_OF_SUB_FOLDERS="$((NO_OF_FOLDERS - 1))"
[ -z "${SKIP_SUBDIRS}" ] && _clear_line 1
[ "${NO_OF_SUB_FOLDERS}" = 0 ] && SKIP_SUBDIRS="true"

"${EXTRA_LOG}" "justify" "Indexing files.." "-"
FILENAMES="$(_tmp='find "'${input}'" -type f -name "*" '${INCLUDE_FILES}' '${EXCLUDE_FILES}'' && eval "${_tmp}")"
FILENAMES="$(find "${input}" -type f)"

# include or exlude the files if -in or -ex flag was used, use grep
[ -n "${INCLUDE_FILES}" ] && _tmp_filenames="$(printf "%s\n" "${FILENAMES}" | grep -E "${EXCLUDE_FILES}")" &&
FILENAMES="${_tmp_filenames}"
[ -n "${EXCLUDE_FILES}" ] && _tmp_filenames="$(printf "%s\n" "${FILENAMES}" | grep -Ev "${EXCLUDE_FILES}")" &&
FILENAMES="${_tmp_filenames}"

_clear_line 1

# Skip the sub folders and find recursively all the files and upload them.
Expand Down
12 changes: 6 additions & 6 deletions src/common/upload-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -404,32 +404,32 @@ EOF

_parser_setup_flag "-in --include" 1 required "pattern"
_parser_setup_flag_help \
"Only include the files with the given pattern to upload - Applicable for folder uploads.
"Only upload the files which contains the given pattern - Applicable for folder uploads.
e.g: ${0##*/} local_folder --include '*1*', will only include with files with pattern '1' in the name."
e.g: ${0##*/} local_folder --include 1, will only include with files with pattern 1 in the name. Regex can be used which works with grep -E command."

_parser_setup_flag_preprocess 4<< 'EOF'
unset INCLUDE_FILES
EOF

_parser_setup_flag_process 4<< 'EOF'
INCLUDE_FILES="${INCLUDE_FILES} -name '${2}' " && _parser_shift
export INCLUDE_FILES="${INCLUDE_FILES:+${INCLUDE_FILES}|}${2}" && _parser_shift
EOF

###################################################

_parser_setup_flag "-ex --exclude" 1 required "pattern"
_parser_setup_flag_help \
"Exclude the files with the given pattern from uploading. - Applicable for folder uploads.
"Only download the files which does not contain the given pattern - Applicable for folder downloads.
e.g: ${0##*/} local_folder --exclude "*1*", will exclude all the files pattern '1' in the name."
e.g: ${0##*/} local_folder --exclude 1, will only include with files with pattern 1 not present in the name. Regex can be used which works with grep -E command."

_parser_setup_flag_preprocess 4<< 'EOF'
unset EXCLUDE_FILES
EOF

_parser_setup_flag_process 4<< 'EOF'
EXCLUDE_FILES="${EXCLUDE_FILES} -name ! '${2}' " && _parser_shift
export EXCLUDE_FILES="${EXCLUDE_FILES:+${EXCLUDE_FILES}|}${2}" && _parser_shift
EOF

###################################################
Expand Down

0 comments on commit 334ecea

Please sign in to comment.