CLOUDSTACK-5900: Failed to delete template/ISO that failed to download.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1c4bbecc Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1c4bbecc Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1c4bbecc Branch: refs/heads/ui-restyle Commit: 1c4bbecc4a50b059b8bb87a802023ee6f48ca1f2 Parents: 1c57dd7 Author: Sanjay Tripathi <sanjay.tripa...@citrix.com> Authored: Wed Jan 29 13:55:44 2014 +0530 Committer: Sanjay Tripathi <sanjay.tripa...@citrix.com> Committed: Wed Jan 29 14:07:59 2014 +0530 ---------------------------------------------------------------------- .../resource/NfsSecondaryStorageResource.java | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1c4bbecc/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java ---------------------------------------------------------------------- diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index 4d11dd3..3d99443 100755 --- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -1716,16 +1716,23 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S parent += File.separator; } String absoluteTemplatePath = parent + relativeTemplatePath; - File tmpltDir = new File(absoluteTemplatePath); + + File tmpltParent; + if(absoluteTemplatePath.endsWith(String.valueOf(obj.getId()))) { + tmpltParent = new File(absoluteTemplatePath); + } else { + tmpltParent = new File(absoluteTemplatePath).getParentFile(); + } + String details = null; - if (!tmpltDir.exists()) { - details = "template parent directory " + tmpltDir.getName() + " doesn't exist"; + if (!tmpltParent.exists()) { + details = "template parent directory " + tmpltParent.getName() + " doesn't exist"; s_logger.debug(details); return new Answer(cmd, true, details); } - File[] tmpltFiles = tmpltDir.listFiles(); + File[] tmpltFiles = tmpltParent.listFiles(); if (tmpltFiles == null || tmpltFiles.length == 0) { - details = "No files under template parent directory " + tmpltDir.getName(); + details = "No files under template parent directory " + tmpltParent.getName(); s_logger.debug(details); } else { boolean found = false; @@ -1751,12 +1758,12 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S } if (!found) { - details = "Can not find template.properties under " + tmpltDir.getName(); + details = "Can not find template.properties under " + tmpltParent.getName(); s_logger.debug(details); } } - if (!tmpltDir.delete()) { - details = "Unable to delete directory " + tmpltDir.getName() + " under Template path " + relativeTemplatePath; + if (!tmpltParent.delete()) { + details = "Unable to delete directory " + tmpltParent.getName() + " under Template path " + relativeTemplatePath; s_logger.debug(details); return new Answer(cmd, false, details); }