Merge lp:~vorlon/livecd-rootfs/many-loops into lp:livecd-rootfs

Proposed by Steve Langasek
Status: Merged
Approved by: Mathieu Trudel-Lapierre
Approved revision: 1573
Merged at revision: 1637
Proposed branch: lp:~vorlon/livecd-rootfs/many-loops
Merge into: lp:livecd-rootfs
Diff against target: 25 lines (+3/-1)
2 files modified
debian/changelog (+2/-0)
live-build/functions (+1/-1)
To merge this branch: bzr merge lp:~vorlon/livecd-rootfs/many-loops
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre Approve
Review via email: mp+332598@code.launchpad.net

Description of the change

Fix handling of our loop device names when our dev is >= loop10.

This is not at all extraordinary on a system which has snap packages installed.

To post a comment you must log in.
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) :
review: Approve
Revision history for this message
Balint Reczey (rbalint) :
Revision history for this message
Steve Langasek (vorlon) wrote :

On Tue, Mar 06, 2018 at 09:55:35AM -0000, Balint Reczey wrote:
> > === modified file 'live-build/functions'
> > --- live-build/functions 2017-10-10 12:23:30 +0000
> > +++ live-build/functions 2017-10-21 07:56:48 +0000
> > @@ -56,7 +56,7 @@

> > # Find the loop device
> > loop_p1="$(echo -e ${kpartx_mapping} | head -n1 | awk '{print$3}')"
> > - loop_device="/dev/loop$(echo ${loop_p1} | cut -b5)"
> > + loop_device="/dev/${loop_p1%p[0-9]*}"

> This works which is a bit a bit confusing, since loop_p1%%p[0-9]* is documented in bash(1) to cover the longest matching pattern and ...%... is to cover shortest expansion.
> In dash(1) the result seems to be undefined but it works:
> ...
> If parameter is * or @, the result of the expansion is
> unspecified.
> ...

> $ dash -c 'TEST=loop43p2140 ; echo ${TEST%p[0-9]*}'
> loop43

> Maybe using sed would be more future-proof.

I think this is a question of confusing documentation, not undefined
behavior. The actual behavior of '%p[0-9]*' is to strip off the last
occurrence of the letter p which is followed immediately by a digit, and any
characters after that. This is only relevant if there is more than one
occurrence of p[0-9] in the string. For example, if loop_p1 was
foo5p12and_also_p6_and_a_half, ${loop_p1%p[0-9]*} evaluates to
foo5p12and_also_, whereas ${loop_p1%%p[0-9]*} evaluates to foo5.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2017-10-19 06:20:19 +0000
3+++ debian/changelog 2017-10-21 07:56:48 +0000
4@@ -1,6 +1,8 @@
5 livecd-rootfs (2.479) UNRELEASED; urgency=medium
6
7 * Purge initramfs-tools from minimized images.
8+ * Properly handle loop device names when there are > 10 devices on the
9+ system.
10
11 -- Steve Langasek <steve.langasek@ubuntu.com> Fri, 13 Oct 2017 17:14:58 -0400
12
13
14=== modified file 'live-build/functions'
15--- live-build/functions 2017-10-10 12:23:30 +0000
16+++ live-build/functions 2017-10-21 07:56:48 +0000
17@@ -56,7 +56,7 @@
18
19 # Find the loop device
20 loop_p1="$(echo -e ${kpartx_mapping} | head -n1 | awk '{print$3}')"
21- loop_device="/dev/loop$(echo ${loop_p1} | cut -b5)"
22+ loop_device="/dev/${loop_p1%p[0-9]*}"
23 if [ ! -b ${loop_device} ]; then
24 echo "unable to find loop device for ${backing_img}"
25 exit 1

Subscribers

People subscribed via source and target branches