mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-07-01 02:36:52 +00:00
now really fix windows
This commit is contained in:
@@ -43,7 +43,7 @@ except ImportError:
|
|||||||
if platform.system() == "OpenBSD":
|
if platform.system() == "OpenBSD":
|
||||||
SUDO = ["/usr/bin/doas"]
|
SUDO = ["/usr/bin/doas"]
|
||||||
elif platform.system() == "Windows":
|
elif platform.system() == "Windows":
|
||||||
SUDO = ["Start-Process", "powershell", "-Verb", "runAs"]
|
SUDO = ["powershell", "Start-Process", "powershell", "-Verb", "runAs"]
|
||||||
else:
|
else:
|
||||||
SUDO = ["/usr/bin/env", "sudo"]
|
SUDO = ["/usr/bin/env", "sudo"]
|
||||||
|
|
||||||
@@ -1282,7 +1282,7 @@ def move_hosts_file_into_place(final_file):
|
|||||||
|
|
||||||
filename = os.path.abspath(final_file.name)
|
filename = os.path.abspath(final_file.name)
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
target_file = Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts"
|
target_file = str(Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts")
|
||||||
else:
|
else:
|
||||||
target_file = "/etc/hosts"
|
target_file = "/etc/hosts"
|
||||||
|
|
||||||
@@ -1299,13 +1299,11 @@ def move_hosts_file_into_place(final_file):
|
|||||||
print_failure(f"Replacing content of {target_file} failed.")
|
print_failure(f"Replacing content of {target_file} failed.")
|
||||||
return False
|
return False
|
||||||
elif platform.system() == "Linux" or platform.system() == "Windows":
|
elif platform.system() == "Linux" or platform.system() == "Windows":
|
||||||
|
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Replacing {target_file} requires root privileges. You might need to enter your password."
|
f"Replacing {target_file} requires root privileges. You might need to enter your password."
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
subprocess.run(SUDO + ["cp", filename, target_file], check=True)
|
subprocess.run(SUDO + [f"'cp {filename} {target_file}'"], check=True, shell=True)
|
||||||
return True
|
return True
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print_failure(f"Replacing {target_file} failed.")
|
print_failure(f"Replacing {target_file} failed.")
|
||||||
|
|||||||
Reference in New Issue
Block a user