diff --git a/emrun.py b/emrun.py old mode 100755 new mode 100644 index b4c05cf24cf43..80a43e721133f --- a/emrun.py +++ b/emrun.py @@ -684,13 +684,12 @@ def do_POST(self): # Binary file dump/upload handling. Requests to # "stdio.html?file=filename" will write binary data to the given file. data = self.rfile.read(int(self.headers['Content-Length'])) - filename = query[len('file='):] - dump_out_directory = 'dump_out' + filename = unquote_u(query[len('file='):]) + filename = os.path.join(emrun_options.dump_out_directory, os.path.normpath(filename)) try: - os.mkdir(dump_out_directory) + os.makedirs(os.path.dirname(filename)) except OSError: pass - filename = os.path.join(dump_out_directory, os.path.normpath(filename)) with open(filename, 'wb') as fh: fh.write(data) logi('Wrote ' + str(len(data)) + ' bytes to file "' + filename + '".') @@ -1571,6 +1570,9 @@ def run(): parser.add_argument('--private_browsing', action='store_true', help='If specified, opens browser in private/incognito mode.') + parser.add_argument('--dump_out_directory', default='dump_out', type=str, + help='If specified, overrides the directory for dump files using emrun_file_dump method.') + parser.add_argument('serve', nargs='?', default='') parser.add_argument('cmdlineparams', nargs='*') diff --git a/tests/test_browser.py b/tests/test_browser.py index a82e8f1a559f8..a456dd8bb572c 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -5330,12 +5330,17 @@ def test_emrun(self): for args in [ args_base, - args_base + ['--private_browsing', '--port', '6941'] + args_base + ['--private_browsing', '--port', '6941'], + args_base + ['--dump_out_directory', 'other dir/multiple', '--port', '6942'] ]: args += [self.in_dir('hello_world.html'), '--', '1', '2', '--3'] print(shared.shlex_join(args)) proc = self.run_process(args, check=False) self.assertEqual(proc.returncode, 100) + dump_dir = 'other dir/multiple' if '--dump_out_directory' in args else 'dump_out' + self.assertExists(self.in_dir(f'{dump_dir}/test.dat')) + self.assertExists(self.in_dir(f'{dump_dir}/heap.dat')) + self.assertExists(self.in_dir(f'{dump_dir}/nested/with space.dat')) stdout = read_file(self.in_dir('stdout.txt')) stderr = read_file(self.in_dir('stderr.txt')) self.assertContained('argc: 4', stdout) diff --git a/tests/test_emrun.c b/tests/test_emrun.c index bc017ae4387df..6bc280b8c3661 100644 --- a/tests/test_emrun.c +++ b/tests/test_emrun.c @@ -18,6 +18,7 @@ int main(int argc, char **argv) { // Dump a file to local filesystem with emrun. EM_ASM(emrun_file_dump("test.dat", HEAPU8.subarray(0, 128));); EM_ASM(emrun_file_dump("heap.dat", HEAPU8)); + EM_ASM(emrun_file_dump("nested/with space.dat", HEAPU8.subarray(128, 256));); if (argc <= 1) exit(1);