ensure existing files are deleted before upgrade

This commit is contained in:
Nathan Freitas 2014-04-08 15:31:02 -04:00
parent 25f4ac8617
commit e8116f4542
1 changed files with 9 additions and 17 deletions

View File

@ -47,51 +47,43 @@ public class TorResourceInstaller implements TorServiceConstants {
InputStream is; InputStream is;
File outFile; File outFile;
if (!installFolder.exists())
installFolder.mkdirs(); installFolder.mkdirs();
Shell shell = Shell.startShell(new ArrayList<String>(),installFolder.getCanonicalPath()); Shell shell = Shell.startShell(new ArrayList<String>(),installFolder.getAbsolutePath());
is = context.getResources().openRawResource(R.raw.torrc); is = context.getResources().openRawResource(R.raw.torrc);
outFile = new File(installFolder, TORRC_ASSET_KEY); outFile = new File(installFolder, TORRC_ASSET_KEY);
if (outFile.exists()) shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand("rm " + outFile.getCanonicalPath())).waitForFinish();
streamToFile(is,outFile, false, false); streamToFile(is,outFile, false, false);
is = context.getResources().openRawResource(R.raw.torrctether); is = context.getResources().openRawResource(R.raw.torrctether);
outFile = new File(installFolder, TORRC_TETHER_KEY); outFile = new File(installFolder, TORRC_TETHER_KEY);
if (outFile.exists()) shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand("rm " + outFile.getCanonicalPath())).waitForFinish();
streamToFile(is, outFile, false, false); streamToFile(is, outFile, false, false);
is = context.getResources().openRawResource(R.raw.privoxy_config); is = context.getResources().openRawResource(R.raw.privoxy_config);
outFile = new File(installFolder, PRIVOXYCONFIG_ASSET_KEY); outFile = new File(installFolder, PRIVOXYCONFIG_ASSET_KEY);
if (outFile.exists()) shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand("rm " + outFile.getCanonicalPath())).waitForFinish();
streamToFile(is,outFile, false, false); streamToFile(is,outFile, false, false);
is = context.getResources().openRawResource(R.raw.tor); is = context.getResources().openRawResource(R.raw.tor);
outFile = new File(installFolder, TOR_ASSET_KEY); outFile = new File(installFolder, TOR_ASSET_KEY);
if (outFile.exists()) shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand("rm " + outFile.getCanonicalPath())).waitForFinish();
streamToFile(is,outFile, false, true); streamToFile(is,outFile, false, true);
is = context.getResources().openRawResource(R.raw.privoxy); is = context.getResources().openRawResource(R.raw.privoxy);
outFile = new File(installFolder, PRIVOXY_ASSET_KEY); outFile = new File(installFolder, PRIVOXY_ASSET_KEY);
if (outFile.exists()) shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand("rm " + outFile.getCanonicalPath())).waitForFinish();
streamToFile(is,outFile, false, true); streamToFile(is,outFile, false, true);
is = context.getResources().openRawResource(R.raw.obfsproxy); is = context.getResources().openRawResource(R.raw.obfsproxy);
outFile = new File(installFolder, OBFSPROXY_ASSET_KEY); outFile = new File(installFolder, OBFSPROXY_ASSET_KEY);
if (outFile.exists()) shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand("rm " + outFile.getCanonicalPath())).waitForFinish();
streamToFile(is,outFile, false, true); streamToFile(is,outFile, false, true);
is = context.getResources().openRawResource(R.raw.xtables); is = context.getResources().openRawResource(R.raw.xtables);
outFile = new File(installFolder, IPTABLES_ASSET_KEY); outFile = new File(installFolder, IPTABLES_ASSET_KEY);
if (outFile.exists()) shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand("rm " + outFile.getCanonicalPath())).waitForFinish();
streamToFile(is,outFile, false, true); streamToFile(is,outFile, false, true);
return true; return true;