MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / restore_backup

Function restore_backup

Scripts/Developer Base/Mobile Developer Setup.py:431–457  ·  view source on GitHub ↗

Restore settings from a backup tar.gz. This will overwrite your current files for those settings.

(backup_path: Path)

Source from the content-addressed store, hash-verified

429 except FileNotFoundError:
430 return ""
431 except UnicodeDecodeError:
432 return path.read_text(encoding="utf-8", errors="replace")
433
434
435def atomic_write_text(path: Path, content: str, mode: int = 0o644) -> None:
436 path.parent.mkdir(parents=True, exist_ok=True)
437 fd, temp_name = tempfile.mkstemp(prefix=path.name + ".", dir=str(path.parent))
438 temp_path = Path(temp_name)
439 try:
440 with os.fdopen(fd, "w", encoding="utf-8") as f:
441 f.write(content)
442 f.flush()
443 os.fsync(f.fileno())
444 os.chmod(temp_path, mode)
445 temp_path.replace(path)
446 finally:
447 temp_path.unlink(missing_ok=True)
448
449
450def sha256_file(path: Path) -> str:
451 h = hashlib.sha256()
452 with path.open("rb") as f:
453 for chunk in iter(lambda: f.read(1024 * 1024), b""):
454 h.update(chunk)
455 return h.hexdigest()
456
457
458def now_stamp() -> str:
459 # Include sub-second precision so multiple backups in one second cannot collide.
460 return time.strftime("%Y%m%d-%H%M%S") + f"-{time.time_ns() % 1_000_000:06d}"

Callers 1

restore_and_removeFunction · 0.70

Calls 4

printFunction · 0.85
headerFunction · 0.70
cFunction · 0.70
bashFunction · 0.70

Tested by

no test coverage detected