Fixed downloader bugs related to temp file name
This commit is contained in:
@@ -2,10 +2,8 @@ import asyncio
|
|||||||
import aiofiles
|
import aiofiles
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import threading
|
import threading
|
||||||
import traceback
|
from uuid import uuid4
|
||||||
import random
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
@@ -36,7 +34,7 @@ class ClientDownloader:
|
|||||||
config: MatrixBotConfig,
|
config: MatrixBotConfig,
|
||||||
client: AsyncClient) -> None:
|
client: AsyncClient) -> None:
|
||||||
"""
|
"""
|
||||||
Setup the sender.
|
Setup the downloader.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
- config - config to use
|
- config - config to use
|
||||||
@@ -218,14 +216,12 @@ class ClientDownloader:
|
|||||||
if key is not None and iv is not None and sha256 is not None:
|
if key is not None and iv is not None and sha256 is not None:
|
||||||
# on disk
|
# on disk
|
||||||
if isinstance(result, Path):
|
if isinstance(result, Path):
|
||||||
r = unpaddedbase64.encode_base64(random.randbytes(8))
|
|
||||||
temp_path = result.with_name(
|
temp_path = result.with_name(
|
||||||
f".{result.name}.{int(time.time())}{r}.tmp"
|
f".{result.name}.{uuid4().hex}.tmp"
|
||||||
)
|
)
|
||||||
await self._decrypt_file(
|
await self._decrypt_file(
|
||||||
result, temp_path, key, iv, sha256
|
result, temp_path, key, iv, sha256
|
||||||
)
|
)
|
||||||
result.unlink()
|
|
||||||
temp_path.replace(result)
|
temp_path.replace(result)
|
||||||
temp_path = None
|
temp_path = None
|
||||||
# in memory
|
# in memory
|
||||||
|
|||||||
Reference in New Issue
Block a user