Skip to contentSkip to conversation

Fix cp's target path for ext* filesystems

PATCH Superseded Leonardo Augusto 2 participants 3 messages Feb 8, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Fix cp's target path for ext* filesystems

Python subprocess' shell=True defaults to /bin/sh[1][2], which often refers to a POSIX-compliant shell. As the -e flag is not defined in the POSIX standard[3], some shells may interpret "-e" as the first argument to the echo command, causing the rest of the command line to fail.

In this particular case, "echo -e 'cd {}'" is interpreted as "-e cd {}", which causes the first line of the command to fail, and causing cp to always place the source file in the filesystem's root.

This issue only affects "wic cp" for ext* filesystems.

[1] https://docs.python.org/2/library/subprocess.html
[2] https://docs.python.org/3/library/subprocess.html
[3] http://pubs.opengroup.org/onlinepubs/9699919799

---
 scripts/lib/wic/engine.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/lib/wic/engine.py +1 -1
index 4662c665c0..b4be796752 100644
@@ -331,7 +331,7 @@ class Disk:
     def copy(self, src, pnum, path):
         """Copy partition image into wic image."""
         if self.partitions[pnum].fstype.startswith('ext'):
-            cmd = "echo -e 'cd {}\nwrite {} {}' | {} -w {}".\
+            cmd = "echo 'cd {}\nwrite {} {}' | {} -w {}".\
                       format(path, src, os.path.basename(src),
                              self.debugfs, self._get_part_image(pnum))
         else: # fat
Signature · 1 line
2.17.1
#1 lore raw
Quoted 27 lines · Leonardo Augusto

Python subprocess' shell=True defaults to /bin/sh[1][2], which often refers to a POSIX-compliant shell. As the -e flag is not defined in the POSIX standard[3], some shells may interpret "-e" as the first argument to the echo command, causing the rest of the command line to fail.

In this particular case, "echo -e 'cd {}'" is interpreted as "-e cd {}", which causes the first line of the command to fail, and causing cp to always place the source file in the filesystem's root.

This issue only affects "wic cp" for ext* filesystems.

[1] https://docs.python.org/2/library/subprocess.html
[2] https://docs.python.org/3/library/subprocess.html
[3] http://pubs.opengroup.org/onlinepubs/9699919799

---
 scripts/lib/wic/engine.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/lib/wic/engine.py +0 -0
index 4662c665c0..b4be796752 100644

scripts/lib/wic/engine.py class Disk: · line 334

Quoted 5 lines
scripts/lib/wic/engine.py +1 -1
@@ -331,7 +331,7 @@ class Disk:
     def copy(self, src, pnum, path):
         """Copy partition image into wic image."""
         if self.partitions[pnum].fstype.startswith('ext'):
-            cmd = "echo -e 'cd {}\nwrite {} {}' | {} -w {}".\
+            cmd = "echo 'cd {}\nwrite {} {}' | {} -w {}".\

This causes some shell's echos to output a literal \n (two characters, '\' and 'n').

The solution should be to use printf instead of echo...

Cheers,
Andre'

Quoted 6 lines
scripts/lib/wic/engine.py +0 -0
                       format(path, src, os.path.basename(src),
                              self.debugfs, self._get_part_image(pnum))
         else: # fat
Signature · 1 line
2.17.1
#2 lore raw
Quoted 1 line · Leonardo Augusto

[...]

Quoted 13 lines

scripts/lib/wic/engine.py class Disk: · line 334

Quoted 11 lines
scripts/lib/wic/engine.py +1 -1
index 4662c665c0..b4be796752 100644
@@ -331,7 +331,7 @@ class Disk:
     def copy(self, src, pnum, path):
         """Copy partition image into wic image."""
         if self.partitions[pnum].fstype.startswith('ext'):
-            cmd = "echo -e 'cd {}\nwrite {} {}' | {} -w {}".\
+            cmd = "echo 'cd {}\nwrite {} {}' | {} -w {}".\

This causes some shell's echos to output a literal \n (two characters,

'\'

Quoted 3 lines

and 'n').

The solution should be to use printf instead of echo...

Yes, indeed. I've just sent out a v3 based on your suggestion.

Thanks!