Permalink
Browse files

Removed an "unsafe" delete method from Utils and replaced invocations…

… to it with a "safe" delete method (one that *does* check the return code from File.delete()).

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1352147 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 8c91799 commit d37d14c7b4730c51fc8b9ecaccad4c8d8f7e94cd @m4rr5 m4rr5 committed Jun 20, 2012
@@ -272,7 +272,10 @@ public DeploymentPackage installDeploymentPackage(InputStream input) throws Depl
}
finally {
if (tempPackage != null) {
- Utils.delete(tempPackage);
+ if (!Utils.delete(tempPackage, true)) {
+ m_log.log(LogService.LOG_ERROR, "Could not delete temporary deployment package from disk");
+ succeeded = false;
+ }
}
if (source != null) {
sendCompleteEvent(source, target, succeeded);
@@ -353,7 +356,10 @@ public void uninstallDeploymentPackage(DeploymentPackage dp, boolean forced) thr
}
File targetPackage = m_context.getDataFile(PACKAGE_DIR + File.separator + source.getName());
- Utils.delete(targetPackage);
+ if (!Utils.delete(targetPackage, true)) {
+ m_log.log(LogService.LOG_ERROR, "Could not delete deployment package from disk");
+ throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not delete deployment package from disk");
+ }
m_packages.remove(dp.getName());
@@ -106,18 +106,6 @@ public static boolean copy(File from, File to) {
return result;
}
-
- public static void delete(File target) {
- // TODO merge with #delete(File, boolean)?!
- if (target.isDirectory()) {
- File[] childs = target.listFiles();
- for (int i = 0; i < childs.length; i++) {
- delete(childs[i]);
- }
- }
- target.delete();
- }
-
public static boolean rename(File from, File to) {
if (!from.renameTo(to)) {
if (copy(from, to)) {
@@ -132,7 +120,7 @@ public static boolean rename(File from, File to) {
return true;
}
- private static boolean delete(File root, boolean deleteRoot) {
+ public static boolean delete(File root, boolean deleteRoot) {
boolean result = true;
if (root.isDirectory()) {
File[] files = root.listFiles();

0 comments on commit d37d14c

Please sign in to comment.