mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-17 06:06:29 +00:00
Fix bug when uploading backup to a mount (#5585)
This commit is contained in:
parent
c8f1b222c0
commit
8b897ba537
@ -233,9 +233,9 @@ class BackupManager(FileConfiguration, JobGroup):
|
|||||||
) -> bool:
|
) -> bool:
|
||||||
"""Load exists backups."""
|
"""Load exists backups."""
|
||||||
|
|
||||||
async def _load_backup(location: str | None, tar_file: Path) -> bool:
|
async def _load_backup(location_name: str | None, tar_file: Path) -> bool:
|
||||||
"""Load the backup."""
|
"""Load the backup."""
|
||||||
backup = Backup(self.coresys, tar_file, "temp", location)
|
backup = Backup(self.coresys, tar_file, "temp", location_name)
|
||||||
if await backup.load():
|
if await backup.load():
|
||||||
if backup.slug in self._backups:
|
if backup.slug in self._backups:
|
||||||
try:
|
try:
|
||||||
@ -251,7 +251,7 @@ class BackupManager(FileConfiguration, JobGroup):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
self._backups[backup.slug] = Backup(
|
self._backups[backup.slug] = Backup(
|
||||||
self.coresys, tar_file, backup.slug, location, backup.data
|
self.coresys, tar_file, backup.slug, location_name, backup.data
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -392,7 +392,13 @@ class BackupManager(FileConfiguration, JobGroup):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Load new backup
|
# Load new backup
|
||||||
backup = Backup(self.coresys, tar_file, backup.slug, location, backup.data)
|
backup = Backup(
|
||||||
|
self.coresys,
|
||||||
|
tar_file,
|
||||||
|
backup.slug,
|
||||||
|
self._get_location_name(location),
|
||||||
|
backup.data,
|
||||||
|
)
|
||||||
if not await backup.load():
|
if not await backup.load():
|
||||||
# Remove invalid backup from location it was moved to
|
# Remove invalid backup from location it was moved to
|
||||||
backup.tarfile.unlink()
|
backup.tarfile.unlink()
|
||||||
|
@ -1054,3 +1054,40 @@ async def test_protected_backup(
|
|||||||
"size_bytes": 10240,
|
"size_bytes": 10240,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures(
|
||||||
|
"path_extern", "mount_propagation", "mock_is_mount", "tmp_supervisor_data"
|
||||||
|
)
|
||||||
|
async def test_upload_to_mount(api_client: TestClient, coresys: CoreSys):
|
||||||
|
"""Test uploading a backup to a specific mount."""
|
||||||
|
await coresys.mounts.load()
|
||||||
|
(coresys.config.path_mounts / "backup_test").mkdir()
|
||||||
|
mount = Mount.from_dict(
|
||||||
|
coresys,
|
||||||
|
{
|
||||||
|
"name": "backup_test",
|
||||||
|
"type": "cifs",
|
||||||
|
"usage": "backup",
|
||||||
|
"server": "backup.local",
|
||||||
|
"share": "backups",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await coresys.mounts.create_mount(mount)
|
||||||
|
|
||||||
|
# Capture our backup initially
|
||||||
|
backup_file = get_fixture_path("backup_example.tar")
|
||||||
|
backup = Backup(coresys, backup_file, "in", None)
|
||||||
|
await backup.load()
|
||||||
|
|
||||||
|
# Upload it and confirm it matches what we had
|
||||||
|
with backup_file.open("rb") as file, MultipartWriter("form-data") as mp:
|
||||||
|
mp.append(file)
|
||||||
|
resp = await api_client.post(
|
||||||
|
"/backups/new/upload?location=backup_test", data=mp
|
||||||
|
)
|
||||||
|
|
||||||
|
assert resp.status == 200
|
||||||
|
body = await resp.json()
|
||||||
|
assert body["data"]["slug"] == "7fed74c8"
|
||||||
|
assert backup == coresys.backups.get("7fed74c8")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user