Skip to contentSkip to conversation

sstate: another fix for touching files inside pseudo

PATCH In review Jose Quaresma 2 participants 3 messages Nov 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sstate: another fix for touching files inside pseudo

This patch is a fixup for 676757f "sstate: fix touching files inside pseudo"

running the 'id' command inside the sstate_unpack_package function shows that this funcion run inside the pseudo:

uid=0(root) gid=0(root) groups=0(root)

The check for [ -w ${SSTATE_PKG} ] and [ -O ${SSTATE_PKG}.siginfo ] will always return true and the touch can fail when the real user don't have permission or in readonly filesystem.

As the documentation refers:
- the file test operator "-w" check if the file has write permission (for the user running the test).
- the file test operator "-O" check if you are owner of file

We can avoid this test running the touch and mask any return errors that we have.

---
 meta/classes/sstate.bbclass | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
meta/classes/sstate.bbclass +6 -6
index 8182010047..e4d58639f3 100644
@@ -900,12 +900,12 @@ sstate_unpack_package () {
 	fi
 
 	tar -I "$ZSTD" -xvf ${SSTATE_PKG}
-	# update .siginfo atime on local/NFS mirror
-	[ -O ${SSTATE_PKG}.siginfo ] && [ -w ${SSTATE_PKG}.siginfo ] && [ -h ${SSTATE_PKG}.siginfo ] && touch -a ${SSTATE_PKG}.siginfo
-	# Use "! -w ||" to return true for read only files
-	[ ! -w ${SSTATE_PKG} ] || touch --no-dereference ${SSTATE_PKG}
-	[ ! -w ${SSTATE_PKG}.sig ] || [ ! -e ${SSTATE_PKG}.sig ] || touch --no-dereference ${SSTATE_PKG}.sig
-	[ ! -w ${SSTATE_PKG}.siginfo ] || [ ! -e ${SSTATE_PKG}.siginfo ] || touch --no-dereference ${SSTATE_PKG}.siginfo
+	# update .siginfo atime on local/NFS mirror if it is a symbolic link
+	[ ! -h ${SSTATE_PKG}.siginfo ] || touch -a ${SSTATE_PKG}.siginfo 2>/dev/null || true
+	# update each symbolic link instead of any referenced file
+	touch --no-dereference ${SSTATE_PKG} 2>/dev/null || true
+	touch --no-dereference ${SSTATE_PKG}.siginfo 2>/dev/null || true
+	[ ! -e ${SSTATE_PKG}.sig ] || touch --no-dereference ${SSTATE_PKG}.sig 2>/dev/null || true
 }
 
 BB_HASHCHECK_FUNCTION = "sstate_checkhashes"
Signature · 1 line
2.33.1
#1 lore raw
Quoted 43 lines

-----Original Message-----
From: [email protected] <openembedded- [email protected]> On Behalf Of Jose Quaresma
Sent: den 4 november 2021 16:42
To: [email protected]
Cc: Jose Quaresma <[email protected]>
Subject: [OE-core] [PATCH] sstate: another fix for touching files inside pseudo

This patch is a fixup for 676757f "sstate: fix touching files inside pseudo"

running the 'id' command inside the sstate_unpack_package function shows that this funcion run inside the pseudo:

uid=0(root) gid=0(root) groups=0(root)

The check for [ -w ${SSTATE_PKG} ] and [ -O ${SSTATE_PKG}.siginfo ] will always return true and the touch can fail when the real user don't have permission or in readonly filesystem.

As the documentation refers:
- the file test operator "-w" check if the file has write permission (for the user running the test).
- the file test operator "-O" check if you are owner of file

We can avoid this test running the touch and mask any return errors that we have.

---
 meta/classes/sstate.bbclass | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
meta/classes/sstate.bbclass +0 -1
index 8182010047..e4d58639f3 100644
@@ -900,12 +900,12 @@ sstate_unpack_package () {
 	fi
 
 	tar -I "$ZSTD" -xvf ${SSTATE_PKG}
-	# update .siginfo atime on local/NFS mirror

meta/classes/sstate.bbclass sstate_unpack_package () { · line 907

Quoted 10 lines
meta/classes/sstate.bbclass +5 -5
-	[ -O ${SSTATE_PKG}.siginfo ] && [ -w ${SSTATE_PKG}.siginfo ] && [ -h ${SSTATE_PKG}.siginfo ] && touch -a ${SSTATE_PKG}.siginfo
-	# Use "! -w ||" to return true for read only files
-	[ ! -w ${SSTATE_PKG} ] || touch --no-dereference ${SSTATE_PKG}
-	[ ! -w ${SSTATE_PKG}.sig ] || [ ! -e ${SSTATE_PKG}.sig ] || touch --no-dereference ${SSTATE_PKG}.sig
-	[ ! -w ${SSTATE_PKG}.siginfo ] || [ ! -e ${SSTATE_PKG}.siginfo ] || touch --no-dereference ${SSTATE_PKG}.siginfo
+	# update .siginfo atime on local/NFS mirror if it is a symbolic link
+	[ ! -h ${SSTATE_PKG}.siginfo ] || touch -a ${SSTATE_PKG}.siginfo 2>/dev/null || true
+	# update each symbolic link instead of any referenced file
+	touch --no-dereference ${SSTATE_PKG} 2>/dev/null || true
+	touch --no-dereference ${SSTATE_PKG}.siginfo 2>/dev/null || true

To match the original code this should be:

	[ ! -e ${SSTATE_PKG}.siginfo ] || touch --no-dereference ${SSTATE_PKG}.siginfo 2>/dev/null || true

Or was there some reason you removed the test for if the siginfo file exists before touching it? If so, then the commit message should state this.

Quoted 6 lines
meta/classes/sstate.bbclass +1 -1
+	[ ! -e ${SSTATE_PKG}.sig ] || touch --no-dereference ${SSTATE_PKG}.sig 2>/dev/null || true
 }
 
 BB_HASHCHECK_FUNCTION = "sstate_checkhashes"
--

2.33.1

//Peter

#2 lore raw

Peter Kjellerstedt <[email protected]> escreveu no dia quinta, 4/11/2021 à(s) 17:01:

Quoted 59 lines
Quoted 39 lines

-----Original Message-----
From: [email protected] <openembedded- [email protected]> On Behalf Of Jose Quaresma
Sent: den 4 november 2021 16:42
To: [email protected]
Cc: Jose Quaresma <[email protected]>
Subject: [OE-core] [PATCH] sstate: another fix for touching files inside pseudo

This patch is a fixup for 676757f "sstate: fix touching files inside pseudo"

running the 'id' command inside the sstate_unpack_package function shows that this funcion run inside the pseudo:

uid=0(root) gid=0(root) groups=0(root)

The check for [ -w ${SSTATE_PKG} ] and [ -O ${SSTATE_PKG}.siginfo ] will always return true and the touch can fail when the real user don't have permission or in readonly filesystem.

As the documentation refers:
- the file test operator "-w" check if the file has write permission (for the user running the test).
- the file test operator "-O" check if you are owner of file

We can avoid this test running the touch and mask any return errors that we have.

---
 meta/classes/sstate.bbclass | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
meta/classes/sstate.bbclass +0 -0
index 8182010047..e4d58639f3 100644

meta/classes/sstate.bbclass sstate_unpack_package () { · line 904

Quoted 5 lines
meta/classes/sstate.bbclass +0 -2
@@ -900,12 +900,12 @@ sstate_unpack_package () {
      fi
 
      tar -I "$ZSTD" -xvf ${SSTATE_PKG}
-     # update .siginfo atime on local/NFS mirror
-     [ -O ${SSTATE_PKG}.siginfo ] && [ -w ${SSTATE_PKG}.siginfo ] && [

-h ${SSTATE_PKG}.siginfo ] && touch -a ${SSTATE_PKG}.siginfo

meta/classes/sstate.bbclass sstate_unpack_package () {

Quoted 3 lines
meta/classes/sstate.bbclass +0 -3
-     # Use "! -w ||" to return true for read only files
-     [ ! -w ${SSTATE_PKG} ] || touch --no-dereference ${SSTATE_PKG}
-     [ ! -w ${SSTATE_PKG}.sig ] || [ ! -e ${SSTATE_PKG}.sig ] || touch

--no-dereference ${SSTATE_PKG}.sig

meta/classes/sstate.bbclass sstate_unpack_package () { · line 908

Quoted 1 line
meta/classes/sstate.bbclass +0 -1
-     [ ! -w ${SSTATE_PKG}.siginfo ] || [ ! -e ${SSTATE_PKG}.siginfo ]
|| touch --no-dereference ${SSTATE_PKG}.siginfo
> +     # update .siginfo atime on local/NFS mirror if it is a symbolic

link

meta/classes/sstate.bbclass sstate_unpack_package () { · line 903

Quoted 1 line
meta/classes/sstate.bbclass +1 -0
+     [ ! -h ${SSTATE_PKG}.siginfo ] || touch -a ${SSTATE_PKG}.siginfo

2>/dev/null || true

meta/classes/sstate.bbclass sstate_unpack_package () { · line 907

Quoted 3 lines
meta/classes/sstate.bbclass +3 -0
+     # update each symbolic link instead of any referenced file
+     touch --no-dereference ${SSTATE_PKG} 2>/dev/null || true
+     touch --no-dereference ${SSTATE_PKG}.siginfo 2>/dev/null || true
Quoted 9 lines

To match the original code this should be:

        [ ! -e ${SSTATE_PKG}.siginfo ] || touch --no-dereference

${SSTATE_PKG}.siginfo 2>/dev/null || true

Or was there some reason you removed the test for if the siginfo file exists before touching it? If so, then the commit message should state this.

I assumed that when ${SSTATE_PKG} exists the ${SSTATE_PKG}.siginfo also exists.
You are true in your observation that this doesn't match the original code. I will send a v2.

Quoted 12 lines

meta/classes/sstate.bbclass sstate_unpack_package () { · line 907

Quoted 2 lines
meta/classes/sstate.bbclass +1 -0
+     [ ! -e ${SSTATE_PKG}.sig ] || touch --no-dereference

${SSTATE_PKG}.sig 2>/dev/null || true

Quoted 5 lines
meta/classes/sstate.bbclass +0 -1
 }
 
 BB_HASHCHECK_FUNCTION = "sstate_checkhashes"
--

2.33.1

//Peter

Signature · 3 lines
Best regards,

José Quaresma