Update public source
This commit is contained in:
+66
-28
@@ -1152,6 +1152,15 @@ class VendorService:
|
|||||||
.upper()
|
.upper()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
len(normalized) != 12
|
||||||
|
or any(
|
||||||
|
character not in "0123456789ABCDEF"
|
||||||
|
for character in normalized
|
||||||
|
)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
|
||||||
for length in (
|
for length in (
|
||||||
9,
|
9,
|
||||||
7,
|
7,
|
||||||
@@ -1200,11 +1209,13 @@ class VendorService:
|
|||||||
"access_points table is missing"
|
"access_points table is missing"
|
||||||
)
|
)
|
||||||
|
|
||||||
columns = {
|
column_info = conn.execute(
|
||||||
row[1]
|
|
||||||
for row in conn.execute(
|
|
||||||
"PRAGMA table_info(access_points)"
|
"PRAGMA table_info(access_points)"
|
||||||
).fetchall()
|
).fetchall()
|
||||||
|
|
||||||
|
columns = {
|
||||||
|
row[1]
|
||||||
|
for row in column_info
|
||||||
}
|
}
|
||||||
|
|
||||||
required = {
|
required = {
|
||||||
@@ -1212,10 +1223,28 @@ class VendorService:
|
|||||||
"vendor"
|
"vendor"
|
||||||
}
|
}
|
||||||
|
|
||||||
if not required.issubset(
|
primary_key_columns = [
|
||||||
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(
|
raise ValueError(
|
||||||
"Invalid WiFi database schema"
|
"Invalid WiFi database schema"
|
||||||
)
|
)
|
||||||
@@ -1723,6 +1752,35 @@ class VendorService:
|
|||||||
f"{database_type}-"
|
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(
|
backups = sorted(
|
||||||
self.backup_directory.glob(
|
self.backup_directory.glob(
|
||||||
f"{prefix}*.sqlite*"
|
f"{prefix}*.sqlite*"
|
||||||
@@ -1731,32 +1789,12 @@ class VendorService:
|
|||||||
reverse=True
|
reverse=True
|
||||||
)
|
)
|
||||||
|
|
||||||
while len(
|
for old_backup in backups[self.BACKUP_LIMIT:]:
|
||||||
backups
|
|
||||||
) >= self.BACKUP_LIMIT:
|
|
||||||
|
|
||||||
oldest = backups.pop()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
oldest.unlink()
|
old_backup.unlink()
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
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
|
return backup
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user