Rename Utils.copy and Utils.symlinkOrCopyFile to indicate exception clobbering

Renamed to Utils.copyQuietly() and Utils.symlinkOrCopyFileQuietly().

The copy(File, File) method gobbles up IOExceptions, whereas the other
copy(InputStream, OupputStream) method doesn't. This could cause confusion,
whereas developers using one may not realise it is is gobblign their
exceptions.
This commit is contained in:
Peter Serwylo 2015-09-10 06:13:28 +10:00
parent a09587c7e2
commit 645f9fc5e3
3 changed files with 8 additions and 11 deletions

View File

@ -48,7 +48,6 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@ -143,8 +142,8 @@ public final class Utils {
/**
* Attempt to symlink, but if that fails, it will make a copy of the file.
*/
public static boolean symlinkOrCopyFile(SanitizedFile inFile, SanitizedFile outFile) {
return FileCompat.symlink(inFile, outFile) || copy(inFile, outFile);
public static boolean symlinkOrCopyFileQuietly(SanitizedFile inFile, SanitizedFile outFile) {
return FileCompat.symlink(inFile, outFile) || copyQuietly(inFile, outFile);
}
/**
@ -162,7 +161,7 @@ public final class Utils {
}
}
public static boolean copy(File inFile, File outFile) {
public static boolean copyQuietly(File inFile, File outFile) {
InputStream input = null;
OutputStream output = null;
try {

View File

@ -140,7 +140,7 @@ public class LocalRepoManager {
SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir);
SanitizedFile fdroidApkLink = new SanitizedFile(webRoot, "fdroid.client.apk");
attemptToDelete(fdroidApkLink);
if (Utils.symlinkOrCopyFile(apkFile, fdroidApkLink))
if (Utils.symlinkOrCopyFileQuietly(apkFile, fdroidApkLink))
fdroidClientURL = "/" + fdroidApkLink.getName();
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Could not set up F-Droid apk in the webroot", e);
@ -220,7 +220,7 @@ public class LocalRepoManager {
private void symlinkFileElsewhere(String fileName, String symlinkPrefix, File directory) {
SanitizedFile index = new SanitizedFile(directory, fileName);
attemptToDelete(index);
Utils.symlinkOrCopyFile(new SanitizedFile(new File(directory, symlinkPrefix), fileName), index);
Utils.symlinkOrCopyFileQuietly(new SanitizedFile(new File(directory, symlinkPrefix), fileName), index);
}
private void deleteContents(File path) {
@ -249,7 +249,7 @@ public class LocalRepoManager {
if (app.installedApk != null) {
SanitizedFile outFile = new SanitizedFile(repoDir, app.installedApk.apkName);
if (Utils.symlinkOrCopyFile(app.installedApk.installedFile, outFile))
if (Utils.symlinkOrCopyFileQuietly(app.installedApk.installedFile, outFile))
continue;
}
// if we got here, something went wrong

View File

@ -21,7 +21,6 @@
package org.fdroid.fdroid.net;
import android.content.Context;
import android.os.Build;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -39,7 +38,6 @@ import org.fdroid.fdroid.data.SanitizedFile;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
/**
@ -188,7 +186,7 @@ public class ApkDownloader implements AsyncDownloader.Listener {
// Can we use the cached version?
if (verifyOrDelete(potentiallyCachedFile)) {
delete(localFile);
Utils.copy(potentiallyCachedFile, localFile);
Utils.copyQuietly(potentiallyCachedFile, localFile);
prepareApkFileAndSendCompleteMessage();
return false;
}
@ -243,7 +241,7 @@ public class ApkDownloader implements AsyncDownloader.Listener {
private void cacheIfRequired() {
if (Preferences.get().shouldCacheApks()) {
Utils.DebugLog(TAG, "Copying .apk file to cache at " + potentiallyCachedFile.getAbsolutePath());
Utils.copy(localFile, potentiallyCachedFile);
Utils.copyQuietly(localFile, potentiallyCachedFile);
}
}