From ef9358023f734007a240e3076f642bd5ad737406 Mon Sep 17 00:00:00 2001 From: Faisal Hameed Date: Tue, 19 Apr 2016 18:27:48 +0500 Subject: [PATCH] Fixing squid:S1066 - Collapsible "if" statements should be merged. --- .../java/com/threerings/getdown/data/Resource.java | 12 ++++-------- .../getdown/launcher/GetdownAppletConfig.java | 6 ++---- .../com/threerings/getdown/net/Downloader.java | 14 +++++--------- .../com/threerings/getdown/tools/DigesterTask.java | 6 ++---- .../java/com/threerings/getdown/tools/Patcher.java | 6 ++---- .../java/com/threerings/getdown/util/FileUtil.java | 14 +++++--------- 6 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/threerings/getdown/data/Resource.java b/src/main/java/com/threerings/getdown/data/Resource.java index 0cb18bc..bedec35 100644 --- a/src/main/java/com/threerings/getdown/data/Resource.java +++ b/src/main/java/com/threerings/getdown/data/Resource.java @@ -141,10 +141,8 @@ public class Resource */ public void clearMarker () { - if (_marker.exists()) { - if (!_marker.delete()) { - log.warning("Failed to erase marker file '" + _marker + "'."); - } + if (_marker.exists() && !_marker.delete()) { + log.warning("Failed to erase marker file '" + _marker + "'."); } } @@ -178,10 +176,8 @@ public class Resource public void erase () { clearMarker(); - if (_local.exists()) { - if (!_local.delete()) { - log.warning("Failed to erase resource '" + _local + "'."); - } + if (_local.exists() && !_local.delete()) { + log.warning("Failed to erase resource '" + _local + "'."); } } diff --git a/src/main/java/com/threerings/getdown/launcher/GetdownAppletConfig.java b/src/main/java/com/threerings/getdown/launcher/GetdownAppletConfig.java index bfb20ef..4467eab 100644 --- a/src/main/java/com/threerings/getdown/launcher/GetdownAppletConfig.java +++ b/src/main/java/com/threerings/getdown/launcher/GetdownAppletConfig.java @@ -343,10 +343,8 @@ public class GetdownAppletConfig protected void ensureAppdirExists () throws Exception { // if our application directory does not exist, auto-create it - if (!appdir.exists() || !appdir.isDirectory()) { - if (!appdir.mkdirs()) { - throw new Exception("m.create_appdir_failed"); - } + if ((!appdir.exists() || !appdir.isDirectory()) && !appdir.mkdirs()) { + throw new Exception("m.create_appdir_failed"); } } diff --git a/src/main/java/com/threerings/getdown/net/Downloader.java b/src/main/java/com/threerings/getdown/net/Downloader.java index 8989da3..5d811e6 100644 --- a/src/main/java/com/threerings/getdown/net/Downloader.java +++ b/src/main/java/com/threerings/getdown/net/Downloader.java @@ -113,10 +113,8 @@ public abstract class Downloader extends Thread // finally report our download completion if we did not already do so when downloading // our final resource - if (_obs != null && !_complete) { - if (!_obs.downloadProgress(100, 0)) { - return false; - } + if (_obs != null && !_complete && !_obs.downloadProgress(100, 0)) { + return false; } } catch (DownloadAbortedException e) { @@ -154,11 +152,9 @@ public abstract class Downloader extends Thread { // make sure the resource's target directory exists File parent = new File(rsrc.getLocal().getParent()); - if (!parent.exists()) { - if (!parent.mkdirs()) { - log.warning("Failed to create target directory for resource '" + rsrc + "'. " + - "Download will certainly fail."); - } + if (!parent.exists() && !parent.mkdirs()) { + log.warning("Failed to create target directory for resource '" + rsrc + "'. " + + "Download will certainly fail."); } doDownload(rsrc); } diff --git a/src/main/java/com/threerings/getdown/tools/DigesterTask.java b/src/main/java/com/threerings/getdown/tools/DigesterTask.java index 3c065e6..eae447f 100644 --- a/src/main/java/com/threerings/getdown/tools/DigesterTask.java +++ b/src/main/java/com/threerings/getdown/tools/DigesterTask.java @@ -64,11 +64,9 @@ public class DigesterTask extends Task } // make sure _storepass and _keyalias are set, if _storepath is set - if (_storepath != null) { - if (_storepass == null || _storealias == null) { - throw new BuildException( + if (_storepath != null && (_storepass == null || _storealias == null)) { + throw new BuildException( "Must specify both a keystore password and a private key alias."); - } } try { diff --git a/src/main/java/com/threerings/getdown/tools/Patcher.java b/src/main/java/com/threerings/getdown/tools/Patcher.java index cfcd766..96db74a 100644 --- a/src/main/java/com/threerings/getdown/tools/Patcher.java +++ b/src/main/java/com/threerings/getdown/tools/Patcher.java @@ -106,10 +106,8 @@ public class Patcher // make sure the file's parent directory exists File pdir = target.getParentFile(); - if (!pdir.exists()) { - if (!pdir.mkdirs()) { - log.warning("Failed to create parent for '" + target + "'."); - } + if (!pdir.exists() && !pdir.mkdirs()) { + log.warning("Failed to create parent for '" + target + "'."); } InputStream in = null; diff --git a/src/main/java/com/threerings/getdown/util/FileUtil.java b/src/main/java/com/threerings/getdown/util/FileUtil.java index 49bd008..fe57d30 100644 --- a/src/main/java/com/threerings/getdown/util/FileUtil.java +++ b/src/main/java/com/threerings/getdown/util/FileUtil.java @@ -38,17 +38,13 @@ public class FileUtil extends com.samskivert.util.FileUtil // place and then delete the old file if (dest.exists()) { File temp = new File(dest.getPath() + "_old"); - if (temp.exists()) { - if (!temp.delete()) { - log.warning("Failed to delete old intermediate file " + temp + "."); - // the subsequent code will probably fail - } + if (temp.exists() && !temp.delete()) { + log.warning("Failed to delete old intermediate file " + temp + "."); + // the subsequent code will probably fail } if (dest.renameTo(temp)) { - if (source.renameTo(dest)) { - if (!temp.delete()) { - log.warning("Failed to delete intermediate file " + temp + "."); - } + if (source.renameTo(dest) && !temp.delete()) { + log.warning("Failed to delete intermediate file " + temp + "."); return true; } }