blob: 390e78cc3e7ba794f6430ca87c1b8d570fc380fe [file] [log] [blame]
Joey Armstrongf32accb2024-03-07 17:05:09 -05001#!/usr/bin/env bash
2# -----------------------------------------------------------------------
3# Copyright 2017-2024 Open Networking Foundation Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http:#www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# -----------------------------------------------------------------------
17# SPDX-FileCopyrightText: 2017-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20
21# -----------------------------------------------------------------------
22# Intent: This function will remove junk files (editor temp files, etc)
23# from a given list of files.
24# -----------------------------------------------------------------------
25function filter_files()
26{
27 local -n ref=$1; shift
28 [[ ${#ref[@]} -eq 0 ]] && { return; }
29
30 local -a fyls=("${ref[@]}")
31 ref=()
32
33 ## ------------------------------------------------------
34 ## Iterate by index to avoid whitespace filename problems
35 ## ------------------------------------------------------
36 local max=$((${#fyls[@]} - 1))
37 local idx
38 for idx in $(seq 0 $max);
39 do
40 local val="${fyls[$idx]}"
41 local tmp="${val//[[:blank:]]}"
42 if [[ ${#tmp} -eq 0 ]]; then
43 continue
44 fi
45
46 case "$val" in
47
48 # Skip editor temp files
49 *'#'*) continue ;;
50 *'~') continue ;;
51
52 # Else gather for processing
53 *) ref+=("$val") ;;
54 esac
55 done
56
57 return
58}
59
60# : # ($?==0) for source $script
61
62# [EOF]