Skip to contentSkip to conversation

install.sh: Preserve directory symlinks

PATCH In review Thierry Escande 3 participants 9 messages Mar 13 – Mar 19

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 install.sh: Preserve directory symlinks

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

---
 install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
install.sh +1 -1
index 3e11c4d46f..5d0b7a4933 100644
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
 echo "Installing Xen from '$src' to '$dst'..."
 (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
 rm -rf "$tmp"
 
 echo "All done."
Signature · 10 lines
2.51.0



--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines · Thierry Escande

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

Coincidentally, I hit this last week. I think the commit message should be expanded because it resulted in a non-functioning system. I switched to make debball, but thanks for fixing this.

I saw Ubuntu's /lib -> /usr/lib symlink replaced with a directory for /lib/systemd/system/xen-watchdog-sleep.sh. With /lib broken, systemd (/sbin/init) could not start and boot fails.

The fix was easy - just restoring the /lib symlink.

So maybe add "Replacing the /lib symlink with a directory results in a non-functioning system."?

I thought /var/run was addressed by:

Fixes 9d628ff6cc21 ("tools: Fix install.sh for systemd")

It hasn't been an issue for me since that change.

For /lib a fixes is either:

Fixes e54a6cd6a1f3 ("systemd: Add hooks to stop/start xen-watchdog on suspend/resume")

or

Fixes b34bde262c8c ("systemd: fall back to default system-sleep dir without systemd-devel")

It might have only been the second one that defaulted to /lib causing the problem. Though the issue is more general.

I do think a fixes and backport are warranted. With the commit message updated:

Thanks,
Jason

Quoted 17 lines
---
  install.sh | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
install.sh +1 -1
index 3e11c4d46f..5d0b7a4933 100644
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
  echo "Installing Xen from '$src' to '$dst'..."
  (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
  rm -rf "$tmp"
 
  echo "All done."
#2 lore raw

Hi,

Quoted 15 lines · Jason Andryuk
Quoted 5 lines · Thierry Escande

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

Coincidentally, I hit this last week.  I think the commit message should be expanded because it resulted in a non-functioning system.  I switched to make debball, but thanks for fixing this.

I saw Ubuntu's /lib -> /usr/lib symlink replaced with a directory for / lib/systemd/system/xen-watchdog-sleep.sh.  With /lib broken, systemd (/ sbin/init) could not start and boot fails.

Quoted 8 lines

The fix was easy -  just restoring the /lib symlink.

So maybe add "Replacing the /lib symlink with a directory results in a non-functioning system."?

I thought /var/run was addressed by:

Fixes 9d628ff6cc21 ("tools: Fix install.sh for systemd")

It hasn't been an issue for me since that change.

I thought it was still the case but my current config does not install files in /var/run anymore, so I missed that fix. Thanks for pointing this out.

Quoted 7 lines

For /lib a fixes is either:

Fixes e54a6cd6a1f3 ("systemd: Add hooks to stop/start xen-watchdog on

suspend/resume")

or

Quoted 8 lines
Fixes b34bde262c8c ("systemd: fall back to default system-sleep dir

without systemd-devel")

It might have only been the second one that defaulted to /lib causing the problem.  Though the issue is more general.

I do think a fixes and backport are warranted.  With the commit message updated:

After discussing with Jan, I will send a v2 that uses the more standard option -h instead of --keep-directory-symlink and updates the commit message.

Regards,

--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#3 lore raw
In reply to Thierry Escande
Quoted 14 lines · Thierry Escande

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

---
 install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
install.sh +0 -0
index 3e11c4d46f..5d0b7a4933 100644

install.sh tmp="`mktemp -d`" · line 30

Quoted 5 lines
install.sh +1 -1
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
 echo "Installing Xen from '$src' to '$dst'..."
 (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -

How compatible (between flavors of tar as well as between versions of GNU tar) is use of this option?

Jan

#4 lore raw
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Thierry Escande

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

---
 install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
install.sh +0 -0
index 3e11c4d46f..5d0b7a4933 100644
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
 echo "Installing Xen from '$src' to '$dst'..."
 (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
Quoted 5 lines

install.sh tmp="`mktemp -d`" · line 30

Quoted 2 lines
install.sh +1 -1
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -

How compatible (between flavors of tar as well as between versions of GNU tar) is use of this option?

It's supported by GNU tar since version 1.27 (from ~12 years ago) but it seems to be the only implementation that supports it. BSD and busybox don't support it. I didn't check for other implementations.

I can add a flavor/version check if that makes sense.

Regards,

--
| Vates

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#5 lore raw
Quoted 27 lines · Thierry Escande
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Thierry Escande

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

---
 install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
install.sh +0 -0
index 3e11c4d46f..5d0b7a4933 100644
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
 echo "Installing Xen from '$src' to '$dst'..."
 (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
Quoted 5 lines

install.sh tmp="`mktemp -d`" · line 30

Quoted 2 lines
install.sh +1 -1
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -

How compatible (between flavors of tar as well as between versions of GNU tar) is use of this option?

Quoted 5 lines

It's supported by GNU tar since version 1.27 (from ~12 years ago) but it seems to be the only implementation that supports it. BSD and busybox don't support it. I didn't check for other implementations.

I can add a flavor/version check if that makes sense.

Possibly. One question then is what the behavior was prior to that option having been introduced.

Jan

#6 lore raw
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Thierry Escande
Quoted 23 lines · Jan Beulich
Quoted 14 lines · Thierry Escande

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

---
 install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
install.sh +0 -0
index 3e11c4d46f..5d0b7a4933 100644

install.sh tmp="`mktemp -d`" · line 30

Quoted 5 lines
install.sh +1 -1
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
 echo "Installing Xen from '$src' to '$dst'..."
 (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -

How compatible (between flavors of tar as well as between versions of GNU tar) is use of this option?

Quoted 8 lines
Quoted 5 lines

It's supported by GNU tar since version 1.27 (from ~12 years ago) but it seems to be the only implementation that supports it. BSD and busybox don't support it. I didn't check for other implementations.

I can add a flavor/version check if that makes sense.

Possibly. One question then is what the behavior was prior to that option having been introduced.

From the patch at [1] introducing the option, and more precisely the test done at [2], directory symlinks were simply overwritten.

[1]
https://cgit.git.savannah.gnu.org/cgit/tar.git/commit/?id=2c06a80918019471876956eef4ef22f05c9e0571
[2]
https://cgit.git.savannah.gnu.org/cgit/tar.git/tree/src/extract.c?id=2c06a80918019471876956eef4ef22f05c9e0571#n934

Regards,
Thierry

--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#7 lore raw
Quoted 31 lines · Thierry Escande
Quoted 30 lines · Jan Beulich
Quoted 29 lines · Thierry Escande
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Thierry Escande

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

---
 install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
install.sh +0 -0
index 3e11c4d46f..5d0b7a4933 100644
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
 echo "Installing Xen from '$src' to '$dst'..."
 (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
Quoted 5 lines

install.sh tmp="`mktemp -d`" · line 30

Quoted 2 lines
install.sh +1 -1
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -

How compatible (between flavors of tar as well as between versions of GNU tar) is use of this option?

It's supported by GNU tar since version 1.27 (from ~12 years ago) but it seems to be the only implementation that supports it. BSD and busybox don't support it. I didn't check for other implementations.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I can add a flavor/version check if that makes sense.

Possibly. One question then is what the behavior was prior to that option having been introduced.

From the patch at [1] introducing the option, and more precisely the test done at [2], directory symlinks were simply overwritten.

Which makes it hard to suggest useful behavior when the option is unavailable:
Simply refusing to install isn't nice, but corrupting the installation is perhaps even worse.

I take it that the (presumably) more standard -h doesn't help here?

Jan

Quoted 16 lines

[1]
https://cgit.git.savannah.gnu.org/cgit/tar.git/commit/?id=2c06a80918019471876956eef4ef22f05c9e0571
[2]
https://cgit.git.savannah.gnu.org/cgit/tar.git/tree/src/extract.c?id=2c06a80918019471876956eef4ef22f05c9e0571#n934

Regards,
Thierry

--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#8 lore raw
Quoted 37 lines · Jan Beulich
Quoted 36 lines · Thierry Escande
Quoted 34 lines · Jan Beulich
Quoted 25 lines · Thierry Escande
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Thierry Escande

In various distros (i.e. Debian) some folders like /lib or /var/run are symlinks. Using the tar option --keep-directory-symlink preserves these symlinks.

---
 install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
install.sh +0 -0
index 3e11c4d46f..5d0b7a4933 100644
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
 echo "Installing Xen from '$src' to '$dst'..."
 (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
Quoted 5 lines

install.sh tmp="`mktemp -d`" · line 30

Quoted 2 lines
install.sh +1 -1
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -

How compatible (between flavors of tar as well as between versions of GNU tar) is use of this option?

Quoted 5 lines

It's supported by GNU tar since version 1.27 (from ~12 years ago) but it seems to be the only implementation that supports it. BSD and busybox don't support it. I didn't check for other implementations.

I can add a flavor/version check if that makes sense.

Possibly. One question then is what the behavior was prior to that option having been introduced.

Quoted 8 lines
Quoted 2 lines

From the patch at [1] introducing the option, and more precisely the test done at [2], directory symlinks were simply overwritten.

Which makes it hard to suggest useful behavior when the option is unavailable:
Simply refusing to install isn't nice, but corrupting the installation is perhaps even worse.

I take it that the (presumably) more standard -h doesn't help here?

-h definitely helps but it has the same behavior for files and folders. So if an already existing symlink is meant to be replaced by a file, then it won't. I chose to use the folder specific option.

That being said there is probably no usecase where a real file replaces a symlink in the dist archive. And anyway, that would also stand for folders.

I'll send a v2 with -h.

Regards,

--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech