mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-19 07:06:30 +00:00
Temporary operations for backups take place in destination folder (#4452)
This commit is contained in:
parent
be4a6a1564
commit
1691f0eac7
@ -183,7 +183,15 @@ class Backup(CoreSysAttributes):
|
|||||||
days=self.sys_backups.days_until_stale
|
days=self.sys_backups.days_until_stale
|
||||||
)
|
)
|
||||||
|
|
||||||
def new(self, slug, name, date, sys_type, password=None, compressed=True):
|
def new(
|
||||||
|
self,
|
||||||
|
slug: str,
|
||||||
|
name: str,
|
||||||
|
date: str,
|
||||||
|
sys_type: BackupType,
|
||||||
|
password: str | None = None,
|
||||||
|
compressed: bool = True,
|
||||||
|
):
|
||||||
"""Initialize a new backup."""
|
"""Initialize a new backup."""
|
||||||
# Init metadata
|
# Init metadata
|
||||||
self._data[ATTR_VERSION] = 2
|
self._data[ATTR_VERSION] = 2
|
||||||
@ -288,7 +296,7 @@ class Backup(CoreSysAttributes):
|
|||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
"""Async context to open a backup."""
|
"""Async context to open a backup."""
|
||||||
self._tmp = TemporaryDirectory(dir=str(self.sys_config.path_tmp))
|
self._tmp = TemporaryDirectory(dir=str(self.tarfile.parent))
|
||||||
|
|
||||||
# create a backup
|
# create a backup
|
||||||
if not self.tarfile.is_file():
|
if not self.tarfile.is_file():
|
||||||
|
22
tests/backups/test_backup.py
Normal file
22
tests/backups/test_backup.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"""Test backups."""
|
||||||
|
|
||||||
|
from os import listdir
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from supervisor.backups.backup import Backup
|
||||||
|
from supervisor.backups.const import BackupType
|
||||||
|
from supervisor.coresys import CoreSys
|
||||||
|
|
||||||
|
|
||||||
|
async def test_new_backup_stays_in_folder(coresys: CoreSys, tmp_path: Path):
|
||||||
|
"""Test making a new backup operates entirely within folder where backup will be stored."""
|
||||||
|
backup = Backup(coresys, tmp_path / "my_backup.tar")
|
||||||
|
backup.new("test", "test", "2023-07-21T21:05:00.000000+00:00", BackupType.FULL)
|
||||||
|
assert not listdir(tmp_path)
|
||||||
|
|
||||||
|
async with backup:
|
||||||
|
assert len(listdir(tmp_path)) == 1
|
||||||
|
assert not backup.tarfile.exists()
|
||||||
|
|
||||||
|
assert len(listdir(tmp_path)) == 1
|
||||||
|
assert backup.tarfile.exists()
|
Loading…
x
Reference in New Issue
Block a user