mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
Separate config dirs from temp dirs
Do not store temporary directories in the Dangerzone's config directory. There are two reasons for that: 1. They are ephemeral, and they need a temporary place to be stored, preferably RAM-backed. 2. We need to set them while running our CI tests.
This commit is contained in:
parent
9b3d98b20b
commit
44c324f9ac
3 changed files with 22 additions and 9 deletions
|
@ -9,10 +9,8 @@ import subprocess
|
|||
import tempfile
|
||||
from typing import Callable, List, Optional, Tuple
|
||||
|
||||
import appdirs
|
||||
|
||||
from ..document import Document
|
||||
from ..util import get_resource_path, get_subprocess_startupinfo
|
||||
from ..util import get_resource_path, get_subprocess_startupinfo, get_tmp_dir
|
||||
from .base import IsolationProvider
|
||||
|
||||
# Define startupinfo for subprocesses
|
||||
|
@ -225,9 +223,7 @@ class Container(IsolationProvider):
|
|||
else:
|
||||
ocr = "0"
|
||||
|
||||
dz_tmp = os.path.join(appdirs.user_config_dir("dangerzone"), "tmp")
|
||||
os.makedirs(dz_tmp, exist_ok=True)
|
||||
|
||||
dz_tmp = get_tmp_dir()
|
||||
tmpdir = tempfile.TemporaryDirectory(dir=dz_tmp)
|
||||
pixel_dir = os.path.join(tmpdir.name, "pixels")
|
||||
safe_dir = os.path.join(tmpdir.name, "safe")
|
||||
|
|
|
@ -9,10 +9,9 @@ import subprocess
|
|||
import sys
|
||||
from typing import Callable, List, Optional
|
||||
|
||||
import appdirs
|
||||
import colorama
|
||||
|
||||
from . import errors
|
||||
from . import errors, util
|
||||
from .document import Document
|
||||
from .isolation_provider.base import IsolationProvider
|
||||
from .settings import Settings
|
||||
|
@ -31,7 +30,7 @@ class DangerzoneCore(object):
|
|||
colorama.init(autoreset=True)
|
||||
|
||||
# App data folder
|
||||
self.appdata_path = appdirs.user_config_dir("dangerzone")
|
||||
self.appdata_path = util.get_config_dir()
|
||||
|
||||
# Languages supported by tesseract
|
||||
with open(get_resource_path("ocr-languages.json"), "r") as f:
|
||||
|
|
|
@ -2,6 +2,24 @@ import pathlib
|
|||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
import appdirs
|
||||
|
||||
|
||||
def get_config_dir() -> str:
|
||||
return appdirs.user_config_dir("dangerzone")
|
||||
|
||||
|
||||
def get_tmp_dir() -> Optional[str]:
|
||||
"""Get the parent dir for the Dangerzone temporary dirs.
|
||||
|
||||
This function returns the parent directory where Dangerzone will store its temporary
|
||||
directories. The default behavior is to let Python choose for us (e.g., in `/tmp`
|
||||
for Linux), which is why we return None. However, we still need to define this
|
||||
function in order to be able to set this dir via mocking in our tests.
|
||||
"""
|
||||
return None
|
||||
|
||||
|
||||
def get_resource_path(filename: str) -> str:
|
||||
|
|
Loading…
Reference in a new issue