Skip to content

Commit 7d33dd6

Browse files
committed
check if output dir is not placed into module to run
1 parent 122df4a commit 7d33dd6

File tree

1 file changed

+12
-3
lines changed
  • graalpython/lib-graalpython/modules/standalone

1 file changed

+12
-3
lines changed

graalpython/lib-graalpython/modules/standalone/__main__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def bundle_python_resources(
164164
def write_folder_to_zipfile(zf, folder, prefix, path_filter=lambda file=None, dir=None: False):
165165
"""
166166
Store a folder with Python modules. We do not store source code, instead,
167-
we for each py file we create a pyc entry rightaway. Any other resources in the
167+
for each py file we create a pyc entry rightaway. Any other resources in the
168168
folder are stored as-is. If data_only is given, neither .py nor .pyc files are
169169
added to the archive.
170170
"""
@@ -225,6 +225,13 @@ def build_binary(targetdir, jc, java_file, ni, parsed_args):
225225
finally:
226226
os.chdir(cwd)
227227

228+
def check_output_directory(parsed_args):
229+
if os.path.abspath(parsed_args.output_directory).startswith(os.path.abspath(parsed_args.module)):
230+
print(
231+
"Output directory cannot be placed inside of module folder to run.",
232+
sep="\n",
233+
)
234+
exit(1)
228235

229236
def main(args):
230237
parser = argparse.ArgumentParser(prog=f"{sys.executable} -m standalone")
@@ -276,6 +283,10 @@ def main(args):
276283

277284
parsed_args = parser.parse_args(args)
278285

286+
preparing_java_project = hasattr(parsed_args, "output_directory")
287+
if preparing_java_project:
288+
check_output_directory(parsed_args)
289+
279290
java_launcher_template = os.path.join(os.path.dirname(__file__), JAVA_LAUNCHER_FILE)
280291
(
281292
resource_zip,
@@ -285,8 +296,6 @@ def main(args):
285296
proj_prefix,
286297
) = parse_path_constants(java_launcher_template)
287298

288-
preparing_java_project = hasattr(parsed_args, "output_directory")
289-
290299
if preparing_java_project:
291300
ni, jc = "", ""
292301
resource_prefix = os.path.join("src", "main", "resources")

0 commit comments

Comments
 (0)