prioritize cwd for downloads if its writable

This commit is contained in:
Concedo 2025-09-22 13:47:50 +08:00
parent f50840455b
commit 08c0246f24

View file

@ -6492,9 +6492,14 @@ def downloader_internal(input_url, output_filename, capture_output, min_file_siz
if "https://huggingface.co/" in input_url and "/blob/main/" in input_url:
input_url = input_url.replace("/blob/main/", "/resolve/main/")
if output_filename == "auto":
exe_dir = os.path.dirname(sys.executable if getattr(sys, 'frozen', False) else __file__)
filename = os.path.basename(input_url).split('?')[0].split('#')[0]
output_filename = os.path.join(exe_dir, filename)
cwd = os.getcwd()
test_writable = os.access(cwd, os.W_OK)
if test_writable:
output_filename = os.path.basename(input_url).split('?')[0].split('#')[0]
else:
exe_dir = os.path.dirname(sys.executable if getattr(sys, 'frozen', False) else __file__)
filename = os.path.basename(input_url).split('?')[0].split('#')[0]
output_filename = os.path.join(exe_dir, filename)
incomplete_dl_exist = (os.path.exists(output_filename+".aria2") and os.path.getsize(output_filename+".aria2") > 16)
if os.path.exists(output_filename) and os.path.getsize(output_filename) > min_file_size and not incomplete_dl_exist:
print(f"{output_filename} already exists, using existing file.")