fetch2: fix handling of `\` in file:// SRC_URI
PATCH 1/1 fetch2: fix handling of `\` in file:// SRC_URI
Using backslashes in file:// URIs was broken.
Either the resolver would fail or the subsequent cp command. Try to avoid this by putting the filenames into quotes.
Fixes https://bugzilla.yoctoproject.org/show_bug.cgi?id=8161
--- lib/bb/fetch2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +1 -1
@@ -1520,7 +1520,7 @@ class FetchMethod(object): if urlpath.find("/") != -1: destdir = urlpath.rsplit("/", 1)[0] + '/' bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir)) - cmd = 'cp -fpPRH %s %s' % (file, destdir) + cmd = "cp -fpPRH '%s' '%s'" % (file, destdir) if not cmd: return
Signature · 1 line
2.26.2
Quoted 16 lines · Leif Middelschulte
Using backslashes in file:// URIs was broken.
Either the resolver would fail or the subsequentcpcommand. Try to avoid this by putting the filenames into quotes.Fixes https://bugzilla.yoctoproject.org/show_bug.cgi?id=8161
Signed-off-by Leif Middelschulte <[email protected]>--- lib/bb/fetch2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/bb/fetch2/__init__.py +0
-0
lib/bb/fetch2/__init__.py class FetchMethod(object): · line 1526
Quoted 8 lines
lib/bb/fetch2/__init__.py +1
-1@@ -1520,7 +1520,7 @@ class FetchMethod(object): if urlpath.find("/") != -1: destdir = urlpath.rsplit("/", 1)[0] + '/' bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir)) - cmd = 'cp -fpPRH %s %s' % (file, destdir) + cmd = "cp -fpPRH '%s' '%s'" % (file, destdir) if not cmd: return
Thanks for the fix. Would you mind adding a test to lib/bb/tests/fetch.py (run with bitbake-selftest) so we can catch this issue in future please?
Cheers,
Richard
PATCH v2 1/2 fetch2: fix handling of `\` in file:// SRC_URI
Using backslashes in file:// URIs was broken.
Either the resolver would fail or the subsequent cp command. Try to avoid this by putting the filenames into quotes.
Fixes https://bugzilla.yoctoproject.org/show_bug.cgi?id=8161
--- lib/bb/fetch2/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +4 -1
@@ -21,6 +21,7 @@ if 'git' not in urllib.parse.uses_netloc: import operator import collections import subprocess +import glob import pickle import errno import bb.persist_data, bb.utils
@@ -1520,7 +1521,9 @@ class FetchMethod(object): if urlpath.find("/") != -1: destdir = urlpath.rsplit("/", 1)[0] + '/' bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir)) - cmd = 'cp -fpPRH %s %s' % (file, destdir) + # do not rely on Shell's glob expansion. + file = ' '.join("'{}'".format(file_path) for file_path in glob.glob(file)) + cmd = 'cp -fpPRH %s "%s"' % (file, destdir) if not cmd: return
Signature · 1 line
2.26.2
lib/bb/fetch2/__init__.py class FetchMethod(object): · line 1526
Quoted 4 lines · Leif Middelschulte
lib/bb/fetch2/__init__.py +3
-1- cmd = 'cp -fpPRH %s %s' % (file, destdir) + # do not rely on Shell's glob expansion. + file = ' '.join("'{}'".format(file_path) for file_path in glob.glob(file)) + cmd = 'cp -fpPRH %s "%s"' % (file, destdir)
Why single quotes in "file" but double quotes in the cmd?
Would it make sense to implement this correctly from the beginning. E.g.
- avoid manual quoting but use "pipes.quote()"
- do not use a shell command string but an array which is given directly to execve()?
Else, next patchset will deal with single/double quotes...
Enrico
Am Montag, den 05.10.2020, 15:29 +0200 schrieb Enrico Scholz:
Quoted 4 lines
CAUTION: This message was sent from outside of KLS Martin. Please do not click links or open attachments unless you recognize the source of this email and know the content is safe.
"Leif Middelschulte" <
[email protected]
Quoted 8 lines
lib/bb/fetch2/__init__.py class FetchMethod(object): · line 1526
Quoted 6 lines
writes:
lib/bb/fetch2/__init__.py +3
-1- cmd = 'cp -fpPRH %s %s' % (file, destdir) + # do not rely on Shell's glob expansion. + file = ' '.join("'{}'".format(file_path) for file_path in glob.glob(file)) + cmd = 'cp -fpPRH %s "%s"' % (file, destdir)Why single quotes in "file" but double quotes in the cmd?
You are correct. It should be double quotes too, to allow variable expansion by the shell. The latest patchset revision uses double quotes for the source too.
Quoted 5 lines
Would it make sense to implement this correctly from the beginning. E.g.
- avoid manual quoting but use "
pipes.quote()"
I assume this would be shlex.quotes?
Quoted 3 lines
- do not use a shell command string but an array which is given directly to
execve()?
AFAII it's desired to be able to reuse other environment variables in SRC_URIs. What's more is that once https://bugs.python.org/issue38893 is fixed, one might want to use python native copy operations anyway.
Quoted 2 lines
Else, next patchset will deal with single/double quotes...
Globbing support was removed. This patchset revision became kind of obsolete.
Quoted 4 lines
Enrico
Thanks for the feedback,
Leif
Quoted 7 lines · Leif
Quoted 4 lines
lib/bb/fetch2/__init__.py class FetchMethod(object): · line 1526
Quoted 2 lines
lib/bb/fetch2/__init__.py +2
-0+ file = ' '.join("'{}'".format(file_path) for file_path in glob.glob(file)) + cmd = 'cp -fpPRH %s "%s"' % (file, destdir)Why single quotes in "file" but double quotes in the cmd?
You are correct. It should be double quotes too, to allow variable expansion by the shell.
Is it really allowed/expected to have environment variables in SRC_URI? E.g. is it expected that
| SRC_URI = "file://$HOME/foo"
works? This fails here because other parts of bitbake (lookup in ${FILESPATH} or in MIRRORS) use this string directly.
Quoted 4 lines
Quoted 3 lines
Would it make sense to implement this correctly from the beginning. E.g.
- avoid manual quoting but use "
pipes.quote()"I assume this would be shlex.quotes?
ok; yes. It is shlex in python3
Quoted 6 lines
Quoted 2 lines
- do not use a shell command string but an array which is given directly to
execve()?AFAII it's desired to be able to reuse other environment variables in
SRC_URIs. What's more is that once https://bugs.python.org/issue38893
is fixed, one might want to use python
But native python operations do not expand environment variables either. Resp. expansion must be done manually which is possible with the "execve([])" way too.
Enrico
PATCH v2 2/2 tests/fetch: backslash support in file:// URIs
In reply to Richard PurdieImplements backslashes in local filenames.
A typical usecase for such a filename is a systemd unit.
Example: dev-disk-by\x2dpath-foo.device
--- lib/bb/tests/fetch.py | 5 +++++ 1 file changed, 5 insertions(+)
lib/bb/tests/fetch.py +5 -0
@@ -584,6 +584,7 @@ class FetcherLocalTest(FetcherTest): touch(os.path.join(self.localsrcdir, 'dir', 'd')) os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir')) touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e')) + touch(os.path.join(self.localsrcdir, 'backslash\x2dsystemd-unit.device')) self.d.setVar("FILESPATH", self.localsrcdir) def fetchUnpack(self, uris):
@@ -601,6 +602,10 @@ class FetcherLocalTest(FetcherTest): tree = self.fetchUnpack(['file://a', 'file://dir/c']) self.assertEqual(tree, ['a', 'dir/c']) + def test_local_backslash(self): + tree = self.fetchUnpack(['file://backslash\\x2dsystemd-unit.device']) + self.assertEqual(tree, ['backslash\\x2dsystemd-unit.device']) + def test_local_wildcard(self): with self.assertRaises(bb.fetch2.ParameterError): tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Signature · 1 line
2.26.2
Re: [bitbake-devel] [PATCH v2 2/2] tests/fetch: backslash support in file:// URIs
Quoted 21 lines · Leif Middelschulte
Implements backslashes in local filenames.
A typical usecase for such a filename is a systemd unit.Example:
dev-disk-by\x2dpath-foo.device--- lib/bb/tests/fetch.py | 5 +++++ 1 file changed, 5 insertions(+)lib/bb/tests/fetch.py +1
-0@@ -584,6 +584,7 @@ class FetcherLocalTest(FetcherTest): touch(os.path.join(self.localsrcdir, 'dir', 'd')) os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir')) touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e')) + touch(os.path.join(self.localsrcdir, 'backslash\x2dsystemd-unit.device')) self.d.setVar("FILESPATH", self.localsrcdir) def fetchUnpack(self, uris):
lib/bb/tests/fetch.py class FetcherLocalTest(FetcherTest): · line 611
Quoted 10 lines
lib/bb/tests/fetch.py +4
-0@@ -601,6 +602,10 @@ class FetcherLocalTest(FetcherTest): tree = self.fetchUnpack(['file://a', 'file://dir/c']) self.assertEqual(tree, ['a', 'dir/c']) + def test_local_backslash(self): + tree = self.fetchUnpack(['file://backslash\\x2dsystemd-unit.device']) + self.assertEqual(tree, ['backslash\\x2dsystemd-unit.device']) + def test_local_wildcard(self): with self.assertRaises(bb.fetch2.ParameterError): tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Thanks for this, looks good. Unfortunately something doesn't seem quite right as the tests fail:
https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/1395/steps/8/logs/step1d
?
Cheers,
Richard
PATCH v3 1/2 fetch2: fix handling of `\` in file:// SRC_URI
Using backslashes in file:// URIs was broken.
Either the resolver would fail or the subsequent cp command. Try to avoid this by putting the filenames into quotes.
Fixes https://bugzilla.yoctoproject.org/show_bug.cgi?id=8161
--- lib/bb/fetch2/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +4 -1
@@ -21,6 +21,7 @@ if 'git' not in urllib.parse.uses_netloc: import operator import collections import subprocess +import glob import pickle import errno import bb.persist_data, bb.utils
@@ -1520,7 +1521,9 @@ class FetchMethod(object): if urlpath.find("/") != -1: destdir = urlpath.rsplit("/", 1)[0] + '/' bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir)) - cmd = 'cp -fpPRH %s %s' % (file, destdir) + # do not rely on Shell's glob expansion. + file = ' '.join("'{}'".format(file_path) for file_path in glob.glob(file)) + cmd = 'cp -fpPRH %s "%s"' % (file, destdir) if not cmd: return
Signature · 1 line
2.26.2
PATCH v3 2/2 tests/fetch: backslash support in file:// URIs
Implements backslashes in local filenames.
A typical usecase for such a filename is a systemd unit.
Example: dev-disk-by\x2dpath-foo.device
--- lib/bb/tests/fetch.py | 5 +++++ 1 file changed, 5 insertions(+)
lib/bb/tests/fetch.py +5 -0
@@ -584,6 +584,7 @@ class FetcherLocalTest(FetcherTest): touch(os.path.join(self.localsrcdir, 'dir', 'd')) os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir')) touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e')) + touch(os.path.join(self.localsrcdir, 'backslash\\x2dsystemd-unit.device')) self.d.setVar("FILESPATH", self.localsrcdir) def fetchUnpack(self, uris):
@@ -601,6 +602,10 @@ class FetcherLocalTest(FetcherTest): tree = self.fetchUnpack(['file://a', 'file://dir/c']) self.assertEqual(tree, ['a', 'dir/c']) + def test_local_backslash(self): + tree = self.fetchUnpack(['file://backslash\\x2dsystemd-unit.device']) + self.assertEqual(tree, ['backslash\\x2dsystemd-unit.device']) + def test_local_wildcard(self): with self.assertRaises(bb.fetch2.ParameterError): tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Signature · 1 line
2.26.2
PATCH v4 1/2 fetch2: fix handling of `\` in file:// SRC_URI
In reply to Richard PurdieUsing backslashes in file:// URIs was broken.
Either the resolver would fail or the subsequent cp command. Try to avoid this by putting the filenames into quotes.
Fixes https://bugzilla.yoctoproject.org/show_bug.cgi?id=8161
--- lib/bb/fetch2/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +4 -1
@@ -21,6 +21,7 @@ if 'git' not in urllib.parse.uses_netloc: import operator import collections import subprocess +import glob import pickle import errno import bb.persist_data, bb.utils
@@ -1520,7 +1521,9 @@ class FetchMethod(object): if urlpath.find("/") != -1: destdir = urlpath.rsplit("/", 1)[0] + '/' bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir)) - cmd = 'cp -fpPRH %s %s' % (file, destdir) + # do not rely on Shell's glob expansion. + file = ' '.join("'{}'".format(file_path) for file_path in glob.glob(file)) + cmd = 'cp -fpPRH %s "%s"' % (file, destdir) if not cmd: return
Signature · 1 line
2.26.2
PATCH v4 1/1 fetch2: fix handling of `\` in file:// SRC_URI
In reply to Richard PurdieThis patch series allows users to specify file:// SRC_URIs containing backslashes (\).
Patch series revision v1:
- Provide simple (using quotes around paths) patch to allow backslahes.
Patch series revision v2:
- Rework simple patch to handle glob expansion inside Python instead of relying on the Shell.
- Provide second patch to test file:// SRC_URIs containing backslashes.
Patch series revision v3:
- Fixup typo in python filename specification.
Patch series revision v4:
- Add missing DCO for patch 2/2.
PATCH v4 2/2 tests/fetch: backslash support in file:// URIs
In reply to Richard PurdieImplements backslashes in local filenames.
A typical usecase for such a filename is a systemd unit.
Example: dev-disk-by\x2dlabel-FOO.device
--- lib/bb/tests/fetch.py | 5 +++++ 1 file changed, 5 insertions(+)
lib/bb/tests/fetch.py +5 -0
@@ -584,6 +584,7 @@ class FetcherLocalTest(FetcherTest): touch(os.path.join(self.localsrcdir, 'dir', 'd')) os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir')) touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e')) + touch(os.path.join(self.localsrcdir, 'backslash\\x2dsystemd-unit.device')) self.d.setVar("FILESPATH", self.localsrcdir) def fetchUnpack(self, uris):
@@ -601,6 +602,10 @@ class FetcherLocalTest(FetcherTest): tree = self.fetchUnpack(['file://a', 'file://dir/c']) self.assertEqual(tree, ['a', 'dir/c']) + def test_local_backslash(self): + tree = self.fetchUnpack(['file://backslash\\x2dsystemd-unit.device']) + self.assertEqual(tree, ['backslash\\x2dsystemd-unit.device']) + def test_local_wildcard(self): with self.assertRaises(bb.fetch2.ParameterError): tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Signature · 1 line
2.26.2
PATCH v5 1/2 fetch2: fix handling of `\` in file:// SRC_URI
In reply to Richard PurdieUsing backslashes in file:// URIs was broken.
Either the resolver would fail or the subsequent cp command. Try to avoid this by putting the filenames into quotes.
Fixes https://bugzilla.yoctoproject.org/show_bug.cgi?id=8161
--- lib/bb/fetch2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +1 -1
@@ -1520,7 +1520,7 @@ class FetchMethod(object): if urlpath.find("/") != -1: destdir = urlpath.rsplit("/", 1)[0] + '/' bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir)) - cmd = 'cp -fpPRH %s %s' % (file, destdir) + cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir) if not cmd: return
Signature · 1 line
2.26.2
PATCH v5 2/2 tests/fetch: backslash support in file:// URIs
Implements backslashes in local filenames.
A typical usecase for such a filename is a systemd unit.
Example: dev-disk-by\x2dlabel-FOO.device
--- lib/bb/tests/fetch.py | 5 +++++ 1 file changed, 5 insertions(+)
lib/bb/tests/fetch.py +5 -0
@@ -584,6 +584,7 @@ class FetcherLocalTest(FetcherTest): touch(os.path.join(self.localsrcdir, 'dir', 'd')) os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir')) touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e')) + touch(os.path.join(self.localsrcdir, r'backslash\x2dsystemd-unit.device')) self.d.setVar("FILESPATH", self.localsrcdir) def fetchUnpack(self, uris):
@@ -601,6 +602,10 @@ class FetcherLocalTest(FetcherTest): tree = self.fetchUnpack(['file://a', 'file://dir/c']) self.assertEqual(tree, ['a', 'dir/c']) + def test_local_backslash(self): + tree = self.fetchUnpack([r'file://backslash\x2dsystemd-unit.device']) + self.assertEqual(tree, [r'backslash\x2dsystemd-unit.device']) + def test_local_wildcard(self): with self.assertRaises(bb.fetch2.ParameterError): tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Signature · 1 line
2.26.2