Skip to contentSkip to conversation

sstate: Fix incorrect return value handling

PATCH In review Richard Purdie 3 participants 4 messages Sep 12, 2014 – Sep 16, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sstate: Fix incorrect return value handling

The use of [ and && here means $? is reset and the exit 1 error interception wasn't working, leading to "file changed as we read it" errors from sstate_create_package when heavily using hardlinks.

Fix this by placing $? into a variable.

meta/classes/sstate.bbclass +2 -1
index 0cb5235..1145a63c 100644
@@ -599,7 +599,8 @@ sstate_create_package () {
 	if [ "$(ls -A)" ]; then
 		set +e
 		tar -czf $TFILE *
-		if [ $? -ne 0 ] && [ $? -ne 1 ]; then
+		ret=$?
+		if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then
 			exit 1
 		fi
 		set -e
#1 lore raw
Quoted 13 lines · Richard Purdie

The use of [ and && here means $? is reset and the exit 1 error interception wasn't working, leading to "file changed as we read it" errors from sstate_create_package when heavily using hardlinks.

Fix this by placing $? into a variable.

meta/classes/sstate.bbclass +0 -0
index 0cb5235..1145a63c 100644

meta/classes/sstate.bbclass sstate_create_package () { · line 603

Quoted 6 lines
meta/classes/sstate.bbclass +2 -1
@@ -599,7 +599,8 @@ sstate_create_package () {
  	if [ "$(ls -A)" ]; then
  		set +e
  		tar -czf $TFILE *
-		if [ $? -ne 0 ] && [ $? -ne 1 ]; then
+		ret=$?
+		if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then

Would changing the line to "if [[ $? -ne 0 && $? -ne 1 ]] " be a better fix?

the best,
thank you

Quoted 5 lines
meta/classes/sstate.bbclass +0 -0
  			exit 1
  		fi
  		set -e
#2 lore raw
Quoted 9 lines · Ming Liu
Quoted 8 lines · Richard Purdie

The use of [ and && here means $? is reset and the exit 1 error interception wasn't working, leading to "file changed as we read it" errors from sstate_create_package when heavily using hardlinks.

Fix this by placing $? into a variable.

Quoted 12 lines

meta/classes/sstate.bbclass sstate_create_package () { · line 603

Quoted 11 lines
meta/classes/sstate.bbclass +2 -1
index 0cb5235..1145a63c 100644
@@ -599,7 +599,8 @@ sstate_create_package () {
      if [ "$(ls -A)" ]; then
          set +e
          tar -czf $TFILE *
-        if [ $? -ne 0 ] && [ $? -ne 1 ]; then
+        ret=$?
+        if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then

Would changing the line to "if [[ $? -ne 0 && $? -ne 1 ]] " be a better fix?

I'm afraid not, "[[" and "&&" in test are bashism.

// Robert

Quoted 9 lines

the best,
thank you

Quoted 5 lines
meta/classes/sstate.bbclass +0 -0
              exit 1
          fi
          set -e
#3 lore raw
Quoted 25 lines · Robert Yang
Quoted 9 lines · Ming Liu
Quoted 8 lines · Richard Purdie

The use of [ and && here means $? is reset and the exit 1 error interception wasn't working, leading to "file changed as we read it" errors from sstate_create_package when heavily using hardlinks.

Fix this by placing $? into a variable.

Quoted 12 lines

meta/classes/sstate.bbclass sstate_create_package () { · line 603

Quoted 11 lines
meta/classes/sstate.bbclass +2 -1
index 0cb5235..1145a63c 100644
@@ -599,7 +599,8 @@ sstate_create_package () {
      if [ "$(ls -A)" ]; then
          set +e
          tar -czf $TFILE *
-        if [ $? -ne 0 ] && [ $? -ne 1 ]; then
+        ret=$?
+        if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then

Would changing the line to "if [[ $? -ne 0 && $? -ne 1 ]] " be a better fix?

Quoted 1 line

I'm afraid not, "[[" and "&&" in test are bashism.

Thanks for pointing it out, please ignore my suggestion then, sorry for the noise.

//Ming Liu

Quoted 14 lines

// Robert

Quoted 9 lines

the best,
thank you

Quoted 5 lines
meta/classes/sstate.bbclass +0 -0
              exit 1
          fi
          set -e