From f60edcd394419a1c3907d1118afdac027bc1bd30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de>
Date: Wed, 19 Apr 2023 12:24:44 +0200
Subject: [PATCH] Delete tor binaries instead of just overwriting them

---
 .../briarproject/onionwrapper/AbstractTorWrapper.java  | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/onionwrapper-core/src/main/java/org/briarproject/onionwrapper/AbstractTorWrapper.java b/onionwrapper-core/src/main/java/org/briarproject/onionwrapper/AbstractTorWrapper.java
index 9973338..a92b8cb 100644
--- a/onionwrapper-core/src/main/java/org/briarproject/onionwrapper/AbstractTorWrapper.java
+++ b/onionwrapper-core/src/main/java/org/briarproject/onionwrapper/AbstractTorWrapper.java
@@ -229,6 +229,10 @@ abstract class AbstractTorWrapper implements EventHandler, TorWrapper {
 			LOG.info("Installing Tor binary for " + architecture);
 		}
 		File torFile = getTorExecutableFile();
+		// Important: delete file here and with other binaries below to prevent
+		// problems on macOS in case the file signature changed.
+		//noinspection ResultOfMethodCallIgnored
+		torFile.delete();
 		extract(getExecutableInputStream("tor"), torFile);
 		if (!torFile.setExecutable(true, true)) throw new IOException();
 	}
@@ -238,6 +242,8 @@ abstract class AbstractTorWrapper implements EventHandler, TorWrapper {
 			LOG.info("Installing libevent binary for " + architecture);
 		}
 		File libEventFile = getLibEventFile();
+		//noinspection ResultOfMethodCallIgnored
+		libEventFile.delete();
 		extract(getExecutableInputStream("libevent-2.1.7.dylib"), libEventFile);
 	}
 
@@ -246,6 +252,8 @@ abstract class AbstractTorWrapper implements EventHandler, TorWrapper {
 			LOG.info("Installing obfs4proxy binary for " + architecture);
 		}
 		File obfs4File = getObfs4ExecutableFile();
+		//noinspection ResultOfMethodCallIgnored
+		obfs4File.delete();
 		extract(getExecutableInputStream("obfs4proxy"), obfs4File);
 		if (!obfs4File.setExecutable(true, true)) throw new IOException();
 	}
@@ -255,6 +263,8 @@ abstract class AbstractTorWrapper implements EventHandler, TorWrapper {
 			LOG.info("Installing snowflake binary for " + architecture);
 		}
 		File snowflakeFile = getSnowflakeExecutableFile();
+		//noinspection ResultOfMethodCallIgnored
+		snowflakeFile.delete();
 		extract(getExecutableInputStream("snowflake"), snowflakeFile);
 		if (!snowflakeFile.setExecutable(true, true)) throw new IOException();
 	}
-- 
GitLab