aboutsummaryrefslogtreecommitdiff
path: root/modules/ui_tempdir.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2024-03-02 07:03:13 +0300
committerAUTOMATIC1111 <16777216c@gmail.com>2024-03-02 07:03:13 +0300
commitbef51aed032c0aaa5cfd80445bc4cf0d85b408b5 (patch)
tree42957c454a4ac8d98488f19811b60359d05d88ba /modules/ui_tempdir.py
parentcf2772fab0af5573da775e7437e6acdca424f26e (diff)
parent13984857890401e8605a3e53bd671e900a18d73f (diff)
Merge branch 'release_candidate'
Diffstat (limited to 'modules/ui_tempdir.py')
-rw-r--r--modules/ui_tempdir.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/modules/ui_tempdir.py b/modules/ui_tempdir.py
index 85015db5..ecd6bdec 100644
--- a/modules/ui_tempdir.py
+++ b/modules/ui_tempdir.py
@@ -35,12 +35,9 @@ def save_pil_to_file(self, pil_image, dir=None, format="png"):
already_saved_as = getattr(pil_image, 'already_saved_as', None)
if already_saved_as and os.path.isfile(already_saved_as):
register_tmp_file(shared.demo, already_saved_as)
- filename = already_saved_as
-
- if not shared.opts.save_images_add_number:
- filename += f'?{os.path.getmtime(already_saved_as)}'
-
- return filename
+ filename_with_mtime = f'{already_saved_as}?{os.path.getmtime(already_saved_as)}'
+ register_tmp_file(shared.demo, filename_with_mtime)
+ return filename_with_mtime
if shared.opts.temp_dir != "":
dir = shared.opts.temp_dir
@@ -86,3 +83,18 @@ def cleanup_tmpdr():
filename = os.path.join(root, name)
os.remove(filename)
+
+
+def is_gradio_temp_path(path):
+ """
+ Check if the path is a temp dir used by gradio
+ """
+ path = Path(path)
+ if shared.opts.temp_dir and path.is_relative_to(shared.opts.temp_dir):
+ return True
+ if gradio_temp_dir := os.environ.get("GRADIO_TEMP_DIR"):
+ if path.is_relative_to(gradio_temp_dir):
+ return True
+ if path.is_relative_to(Path(tempfile.gettempdir()) / "gradio"):
+ return True
+ return False