Skip to content

Commit

Permalink
migration: Remove tor files from prior version on Linux
Browse files Browse the repository at this point in the history
PR bisq-network#2938 unbundles Tor from Bisq on Linux and switches to the OSes Tor
binary. If a user updates from a prior version their data directory will
contain the old extracted Tor binaries. The migration in this change
removes the obsolete files.
  • Loading branch information
alvasw committed Oct 21, 2024
1 parent ff2dca8 commit b220912
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package bisq.application.migration.migrations;

import bisq.common.application.ApplicationVersion;
import bisq.common.file.FileUtils;
import bisq.common.platform.OS;
import bisq.common.platform.Version;

import java.io.IOException;
Expand All @@ -12,6 +14,11 @@ public class MigrationsForV2_1_2 implements Migration {
@Override
public void run(Path dataDir) {
try {
if (OS.isLinux()) {
Path torDataDir = dataDir.resolve("tor");
FileUtils.deleteFileOrDirectory(torDataDir);
}

Path versionFilePath = dataDir.resolve("version");
Files.writeString(versionFilePath, ApplicationVersion.getVersion().toString());
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import bisq.common.application.ApplicationVersion;
import bisq.common.platform.Version;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -25,4 +28,103 @@ void migrationTest(@TempDir Path dataDir) throws IOException {
assertThat(readVersion)
.isEqualTo(ApplicationVersion.getVersion().toString());
}

@Test
@EnabledOnOs({OS.MAC, OS.WINDOWS})
void torFilesRemovalTestOnMacAndWindows(@TempDir Path dataDir) throws IOException {
Path torDataDir = dataDir.resolve("tor");
createFakeTorDataDir(torDataDir);

migrationsForV212.run(dataDir);

assertThat(torDataDir).exists();
boolean fileExists = torDataDir.resolve("libevent-2.1.so.7").toFile().exists();
assertThat(fileExists).isTrue();

Path pluggableTransportDir = torDataDir.resolve("pluggable_transports");
assertThat(pluggableTransportDir).exists();

fileExists = pluggableTransportDir.resolve("README.SNOWFLAKE.md").toFile().exists();
assertThat(fileExists).isTrue();

Path versionFilePath = dataDir.resolve("version");
String version = Files.readString(versionFilePath);
assertThat(version).isEqualTo(ApplicationVersion.getVersion().toString());
}

@Test
@EnabledOnOs(OS.LINUX)
void torFilesRemovalTestOnLinux(@TempDir Path dataDir) throws IOException {
Path torDataDir = dataDir.resolve("tor");
createFakeTorDataDir(torDataDir);

migrationsForV212.run(dataDir);

assertThat(torDataDir).doesNotExist();
boolean fileExists = torDataDir.resolve("libevent-2.1.so.7").toFile().exists();
assertThat(fileExists).isFalse();

Path pluggableTransportDir = torDataDir.resolve("pluggable_transports");
assertThat(pluggableTransportDir).doesNotExist();

fileExists = pluggableTransportDir.resolve("README.SNOWFLAKE.md").toFile().exists();
assertThat(fileExists).isFalse();

Path versionFilePath = dataDir.resolve("version");
String version = Files.readString(versionFilePath);
assertThat(version).isEqualTo(ApplicationVersion.getVersion().toString());
}

private void createFakeTorDataDir(Path torDataDir) {
boolean isSuccess = torDataDir.toFile().mkdirs();
assertThat(isSuccess).isTrue();

List<String> torDirFiles = List.of("lock",
"libssl.so.1.1",
"libstdc++.so.6",
"cached-certs",
"cached-microdesc-consensus",
"state",
"debug.log",
"libevent-2.1.so.7",
"torrc",
"tor",
"cached-microdescs.new",
"geoip",
"version",
"libcrypto.so.1.1",
"keys",
"geoip6");
createFiles(torDataDir, torDirFiles);

Path pluggableTransportDir = torDataDir.resolve("pluggable_transports");
isSuccess = pluggableTransportDir.toFile().mkdirs();
assertThat(isSuccess).isTrue();

List<String> pluggableTransportFiles = List.of("snowflake-client",
"bridges_list.snowflake.txt",
"bridges_list.obfs4.txt",
"README.SNOWFLAKE.md",
"obfs4proxy",
"pt_config.json",
"bridges_list.meek-azure.txt");
createFiles(pluggableTransportDir, pluggableTransportFiles);

boolean fileExists = torDataDir.resolve("libevent-2.1.so.7").toFile().exists();
assertThat(fileExists).isTrue();

fileExists = pluggableTransportDir.resolve("README.SNOWFLAKE.md").toFile().exists();
assertThat(fileExists).isTrue();
}

private void createFiles(Path basePath, List<String> fileNames) {
fileNames.forEach(filename -> {
try {
Path filePath = basePath.resolve(filename);
Files.writeString(filePath, "ABC");
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
}

0 comments on commit b220912

Please sign in to comment.