diff options
author | Murali Mohan Murthy Potham <murali.p@huawei.com> | 2017-10-12 09:47:17 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-10-12 09:47:17 +0000 |
commit | 9f51f2b1be71e42abc181724a27d99b8d2631bf2 (patch) | |
tree | a6b0e4e94d87563f2a5482a1c2b8b09b5d82ffa2 | |
parent | 55c2538b25b1897785948b1b44430a34561f0c34 (diff) | |
parent | 4b71bfa97e9ed4bfeaf38cf9feb1bf5c7549d7b2 (diff) |
Merge "Lower cyclomatic complexity of copyDirectory"
-rw-r--r-- | vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java index e45d31bf..48a7d0ca 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java @@ -34,7 +34,7 @@ public class ToolUtil { } /** - * copy in directory. + * simple copy directory * @param srcDirName source directory name * @param destDirName destination directory name * @param files file list in directory @@ -42,24 +42,44 @@ public class ToolUtil { * @return boolean * @throws IOException e */ - public static boolean copyInDirectory(String srcDirName, String destDirName, File[] files, boolean overlay) + public static boolean simpleCopyDirectory(String srcDirName, String destDirName) throws IOException { + File srcDir = new File(srcDirName); + File[] files = srcDir.listFiles(); for (int i = 0; i < files.length; i++) { boolean flag = false; if (files[i].isFile()) { flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true); } if (files[i].isDirectory()) { - flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay); + flag = simpleCopyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName()); } if (!flag) { String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!"; LOGGER.error(message); return false; } - } - return true; + } + return true; + } + + /** + * create destDir + * @param destDirName destination directory name + * @param overlay overwrite or not + * @return boolean + */ + public static boolean createDestDir(String destDirName, boolean overlay) + { + File destDir = new File(destDirName); + if (destDir.exists() && overlay) { + new File(destDirName).delete(); + } else if (destDir.exists() && !overlay) { + return false; + } + + return destDir.mkdirs(); } /** @@ -77,24 +97,17 @@ public class ToolUtil { return false; } - String useDestDirName = destDirName; - if (!useDestDirName.endsWith(File.separator)) { - useDestDirName += File.separator; - } - File destDir = new File(useDestDirName); - if (destDir.exists() && overlay) { - new File(useDestDirName).delete(); - } else if (destDir.exists() && !overlay) { - return false; + String fullDestDirName = destDirName; + if (!fullDestDirName.endsWith(File.separator)) { + fullDestDirName += File.separator; } - if (!destDir.mkdirs()) { - return false; + if (!createDestDir(fullDestDirName, overlay)) + { + return false; } - File[] files = srcDir.listFiles(); - - return copyInDirectory(srcDirName, destDirName, files, overlay); + return simpleCopyDirectory(srcDirName, fullDestDirName); } /** |