Update public source
This commit is contained in:
+66
-28
@@ -1152,6 +1152,15 @@ class VendorService:
|
||||
.upper()
|
||||
)
|
||||
|
||||
if (
|
||||
len(normalized) != 12
|
||||
or any(
|
||||
character not in "0123456789ABCDEF"
|
||||
for character in normalized
|
||||
)
|
||||
):
|
||||
return None
|
||||
|
||||
for length in (
|
||||
9,
|
||||
7,
|
||||
@@ -1200,11 +1209,13 @@ class VendorService:
|
||||
"access_points table is missing"
|
||||
)
|
||||
|
||||
column_info = conn.execute(
|
||||
"PRAGMA table_info(access_points)"
|
||||
).fetchall()
|
||||
|
||||
columns = {
|
||||
row[1]
|
||||
for row in conn.execute(
|
||||
"PRAGMA table_info(access_points)"
|
||||
).fetchall()
|
||||
for row in column_info
|
||||
}
|
||||
|
||||
required = {
|
||||
@@ -1212,10 +1223,28 @@ class VendorService:
|
||||
"vendor"
|
||||
}
|
||||
|
||||
if not required.issubset(
|
||||
columns
|
||||
):
|
||||
primary_key_columns = [
|
||||
row
|
||||
for row in column_info
|
||||
if row[5] > 0
|
||||
]
|
||||
|
||||
id_column = next(
|
||||
(
|
||||
row
|
||||
for row in column_info
|
||||
if row[1] == "id"
|
||||
),
|
||||
None
|
||||
)
|
||||
|
||||
if (
|
||||
not required.issubset(columns)
|
||||
or id_column is None
|
||||
or id_column[2].upper() != "INTEGER"
|
||||
or id_column[5] != 1
|
||||
or len(primary_key_columns) != 1
|
||||
):
|
||||
raise ValueError(
|
||||
"Invalid WiFi database schema"
|
||||
)
|
||||
@@ -1723,6 +1752,35 @@ class VendorService:
|
||||
f"{database_type}-"
|
||||
)
|
||||
|
||||
timestamp = datetime.now(
|
||||
timezone.utc
|
||||
).strftime(
|
||||
"%Y%m%d-%H%M%S-%f"
|
||||
)
|
||||
|
||||
backup = (
|
||||
self.backup_directory
|
||||
/
|
||||
(
|
||||
f"{prefix}"
|
||||
f"{timestamp}"
|
||||
f".sqlite3"
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
shutil.copy2(
|
||||
database,
|
||||
backup
|
||||
)
|
||||
except Exception:
|
||||
try:
|
||||
backup.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
raise
|
||||
|
||||
backups = sorted(
|
||||
self.backup_directory.glob(
|
||||
f"{prefix}*.sqlite*"
|
||||
@@ -1731,32 +1789,12 @@ class VendorService:
|
||||
reverse=True
|
||||
)
|
||||
|
||||
while len(
|
||||
backups
|
||||
) >= self.BACKUP_LIMIT:
|
||||
|
||||
oldest = backups.pop()
|
||||
|
||||
for old_backup in backups[self.BACKUP_LIMIT:]:
|
||||
try:
|
||||
oldest.unlink()
|
||||
old_backup.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
backup = (
|
||||
self.backup_directory
|
||||
/
|
||||
(
|
||||
f"{prefix}"
|
||||
f"{datetime.now(timezone.utc).strftime('%Y%m%d-%H%M%S')}"
|
||||
f".sqlite3"
|
||||
)
|
||||
)
|
||||
|
||||
shutil.copy2(
|
||||
database,
|
||||
backup
|
||||
)
|
||||
|
||||
return backup
|
||||
|
||||
# ============================================================
|
||||
|
||||
Reference in New Issue
Block a user