diff mbox

utilities: kernelscan.sh: Check that the file exists

Message ID 1352202833-24425-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Nov. 6, 2012, 11:53 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

kernelscan.sh makes assumptions about which files to scan and
this can change over time because files get renamed or removed from
the kernel. So add a check so see if the source exists before trying
to scan it.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/utilities/kernelscan.sh |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Keng-Yu Lin Nov. 8, 2012, 3:05 a.m. UTC | #1
On Tue, Nov 6, 2012 at 12:53 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> kernelscan.sh makes assumptions about which files to scan and
> this can change over time because files get renamed or removed from
> the kernel. So add a check so see if the source exists before trying
> to scan it.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/utilities/kernelscan.sh |   14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/src/utilities/kernelscan.sh b/src/utilities/kernelscan.sh
> index 529d9cc..fd0f662 100755
> --- a/src/utilities/kernelscan.sh
> +++ b/src/utilities/kernelscan.sh
> @@ -41,12 +41,16 @@ fi
>
>  scan_source_file()
>  {
> -       $KERNELSCAN < $1 -E | gcc -E $CONFIGS - | $KERNELSCAN -P > $TMP
> -       if [ $(stat -c%s $TMP) -gt 0 ]; then
> -               echo "Source: $1"
> -               cat $TMP
> +       if [ -f $1 ]; then
> +               $KERNELSCAN < $1 -E | gcc -E $CONFIGS - | $KERNELSCAN -P > $TMP
> +               if [ $(stat -c%s $TMP) -gt 0 ]; then
> +                       echo "Source: $1"
> +                       cat $TMP
> +               fi
> +               rm $TMP
> +       else
> +               echo "Source: $1 does not exist"
>         fi
> -       rm $TMP
>  }
>
>  scan_source_tree()
> --
> 1.7.10.4
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Alex Hung Nov. 21, 2012, 3:20 a.m. UTC | #2
On 11/06/2012 07:53 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> kernelscan.sh makes assumptions about which files to scan and
> this can change over time because files get renamed or removed from
> the kernel. So add a check so see if the source exists before trying
> to scan it.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/utilities/kernelscan.sh |   14 +++++++++-----
>   1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/src/utilities/kernelscan.sh b/src/utilities/kernelscan.sh
> index 529d9cc..fd0f662 100755
> --- a/src/utilities/kernelscan.sh
> +++ b/src/utilities/kernelscan.sh
> @@ -41,12 +41,16 @@ fi
>
>   scan_source_file()
>   {
> -	$KERNELSCAN < $1 -E | gcc -E $CONFIGS - | $KERNELSCAN -P > $TMP
> -	if [ $(stat -c%s $TMP) -gt 0 ]; then
> -		echo "Source: $1"
> -		cat $TMP
> +	if [ -f $1 ]; then
> +		$KERNELSCAN < $1 -E | gcc -E $CONFIGS - | $KERNELSCAN -P > $TMP
> +		if [ $(stat -c%s $TMP) -gt 0 ]; then
> +			echo "Source: $1"
> +			cat $TMP
> +		fi
> +		rm $TMP	
> +	else
> +		echo "Source: $1 does not exist"
>   	fi
> -	rm $TMP
>   }
>
>   scan_source_tree()
>
Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/utilities/kernelscan.sh b/src/utilities/kernelscan.sh
index 529d9cc..fd0f662 100755
--- a/src/utilities/kernelscan.sh
+++ b/src/utilities/kernelscan.sh
@@ -41,12 +41,16 @@  fi
 
 scan_source_file()
 {
-	$KERNELSCAN < $1 -E | gcc -E $CONFIGS - | $KERNELSCAN -P > $TMP
-	if [ $(stat -c%s $TMP) -gt 0 ]; then
-		echo "Source: $1"
-		cat $TMP
+	if [ -f $1 ]; then
+		$KERNELSCAN < $1 -E | gcc -E $CONFIGS - | $KERNELSCAN -P > $TMP
+		if [ $(stat -c%s $TMP) -gt 0 ]; then
+			echo "Source: $1"
+			cat $TMP
+		fi
+		rm $TMP	
+	else
+		echo "Source: $1 does not exist"
 	fi
-	rm $TMP
 }
 
 scan_source_tree()