Skip to content

Commit ac54c94

Browse files
authored
add argument to emrun for file dump_out directory (#15801)
1 parent cc288c7 commit ac54c94

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

emrun.py

100755100644
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,12 @@ def do_POST(self):
684684
# Binary file dump/upload handling. Requests to
685685
# "stdio.html?file=filename" will write binary data to the given file.
686686
data = self.rfile.read(int(self.headers['Content-Length']))
687-
filename = query[len('file='):]
688-
dump_out_directory = 'dump_out'
687+
filename = unquote_u(query[len('file='):])
688+
filename = os.path.join(emrun_options.dump_out_directory, os.path.normpath(filename))
689689
try:
690-
os.mkdir(dump_out_directory)
690+
os.makedirs(os.path.dirname(filename))
691691
except OSError:
692692
pass
693-
filename = os.path.join(dump_out_directory, os.path.normpath(filename))
694693
with open(filename, 'wb') as fh:
695694
fh.write(data)
696695
logi('Wrote ' + str(len(data)) + ' bytes to file "' + filename + '".')
@@ -1571,6 +1570,9 @@ def run():
15711570
parser.add_argument('--private_browsing', action='store_true',
15721571
help='If specified, opens browser in private/incognito mode.')
15731572

1573+
parser.add_argument('--dump_out_directory', default='dump_out', type=str,
1574+
help='If specified, overrides the directory for dump files using emrun_file_dump method.')
1575+
15741576
parser.add_argument('serve', nargs='?', default='')
15751577

15761578
parser.add_argument('cmdlineparams', nargs='*')

tests/test_browser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5330,12 +5330,17 @@ def test_emrun(self):
53305330

53315331
for args in [
53325332
args_base,
5333-
args_base + ['--private_browsing', '--port', '6941']
5333+
args_base + ['--private_browsing', '--port', '6941'],
5334+
args_base + ['--dump_out_directory', 'other dir/multiple', '--port', '6942']
53345335
]:
53355336
args += [self.in_dir('hello_world.html'), '--', '1', '2', '--3']
53365337
print(shared.shlex_join(args))
53375338
proc = self.run_process(args, check=False)
53385339
self.assertEqual(proc.returncode, 100)
5340+
dump_dir = 'other dir/multiple' if '--dump_out_directory' in args else 'dump_out'
5341+
self.assertExists(self.in_dir(f'{dump_dir}/test.dat'))
5342+
self.assertExists(self.in_dir(f'{dump_dir}/heap.dat'))
5343+
self.assertExists(self.in_dir(f'{dump_dir}/nested/with space.dat'))
53395344
stdout = read_file(self.in_dir('stdout.txt'))
53405345
stderr = read_file(self.in_dir('stderr.txt'))
53415346
self.assertContained('argc: 4', stdout)

tests/test_emrun.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int main(int argc, char **argv) {
1818
// Dump a file to local filesystem with emrun.
1919
EM_ASM(emrun_file_dump("test.dat", HEAPU8.subarray(0, 128)););
2020
EM_ASM(emrun_file_dump("heap.dat", HEAPU8));
21+
EM_ASM(emrun_file_dump("nested/with space.dat", HEAPU8.subarray(128, 256)););
2122

2223
if (argc <= 1)
2324
exit(1);

0 commit comments

Comments
 (0)