diff --git a/release/bash/gupload b/release/bash/gupload index b16e233..e10285d 100755 --- a/release/bash/gupload +++ b/release/bash/gupload @@ -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 \ @@ -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 diff --git a/release/sh/gupload b/release/sh/gupload index 9e58aba..0b1b739 100755 --- a/release/sh/gupload +++ b/release/sh/gupload @@ -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 \ @@ -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 diff --git a/src/common/upload-common.sh b/src/common/upload-common.sh index 31d7d9a..69deca4 100644 --- a/src/common/upload-common.sh +++ b/src/common/upload-common.sh @@ -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. diff --git a/src/common/upload-flags.sh b/src/common/upload-flags.sh index 015176f..84c89c4 100644 --- a/src/common/upload-flags.sh +++ b/src/common/upload-flags.sh @@ -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 ###################################################