Skip to content

Commit c3e3e22

Browse files
committed
adding check to make sure it's in the temp dir
1 parent 64f978e commit c3e3e22

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

shiny/_app.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import copy
44
import os
55
import shutil
6+
import tempfile
67
import secrets
78
from contextlib import AsyncExitStack, asynccontextmanager
89
from inspect import signature
@@ -216,14 +217,21 @@ def __init__(
216217
)
217218

218219
def __del__(self):
220+
current_temp_dir = os.path.realpath(tempfile.gettempdir())
221+
219222
user_dependencies = [
220223
v.source["subdir"]
221224
for k, v in self._registered_dependencies.items()
222225
if k.startswith("include-")
223226
]
224227

225228
for item in user_dependencies:
226-
if os.path.exists(item):
229+
# Only remove the item if it exists and it is in the current temp directory
230+
if (
231+
os.path.exists(item)
232+
and os.path.commonprefix([os.path.realpath(item), current_temp_dir])
233+
== current_temp_dir
234+
):
227235
print("Removing dependency: ", item)
228236
shutil.rmtree(item)
229237

0 commit comments

Comments
 (0)