You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/07/16 23:42:44 UTC

git commit: updated refs/heads/master to 9f019ec

Updated Branches:
  refs/heads/master 1b4900a8a -> 9f019ec7c


CLOUDSTACK-2497: Object_Store_Refactor - Snapshots - Not able to delete
snapshots.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9f019ec7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9f019ec7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9f019ec7

Branch: refs/heads/master
Commit: 9f019ec7c3c6a8c9cf9ed4c8eab37e366db0a047
Parents: 1b4900a
Author: Min Chen <mi...@citrix.com>
Authored: Tue Jul 16 14:30:12 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Tue Jul 16 14:42:29 2013 -0700

----------------------------------------------------------------------
 .../resource/NfsSecondaryStorageResource.java   | 35 +++++++++++---------
 1 file changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f019ec7/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 77c019e..88e3784 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
@@ -1269,30 +1269,35 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         DataStoreTO dstore = obj.getDataStore();
         if (dstore instanceof NfsTO) {
             NfsTO nfs = (NfsTO) dstore;
-            String relativeSnapshotPath = obj.getPath();
-            String parent = getRootDir(nfs.getUrl());
-
-            if (relativeSnapshotPath.startsWith(File.separator)) {
-                relativeSnapshotPath = relativeSnapshotPath.substring(1);
+            String snapshotPath = obj.getPath();
+            if (snapshotPath.startsWith(File.separator)) {
+                snapshotPath = snapshotPath.substring(1);
             }
+            int index = snapshotPath.lastIndexOf("/");
+            String snapshotName = snapshotPath.substring(index + 1);
+            snapshotPath = snapshotPath.substring(0, index);
 
+            String parent = getRootDir(nfs.getUrl());
             if (!parent.endsWith(File.separator)) {
                 parent += File.separator;
             }
-            String absoluteSnapshotPath = parent + relativeSnapshotPath;
-            File snapshot = new File(absoluteSnapshotPath);
+            String absoluteSnapshotPath = parent + snapshotPath;
+            // check if directory exists
+            File snapshotDir = new File(absoluteSnapshotPath);
             String details = null;
-            if (!snapshot.exists()) {
-                details = "snapshot file " + snapshot.getName() + " doesn't exist";
+            if (!snapshotDir.exists()) {
+                details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
                 s_logger.debug(details);
-                return new Answer(cmd, true, details);
+                return new Answer(cmd, false, details);
             }
-
-            if (!snapshot.delete()) {
-                return new Answer(cmd, false, "Unable to delete file " + snapshot.getName() + " under install path "
-                        + relativeSnapshotPath);
+            // delete snapshot in the directory if exists
+            String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
+            String result = deleteLocalFile(lPath);
+            if (result != null) {
+                details = "failed to delete snapshot " + lPath + " , err=" + result;
+                s_logger.warn(details);
+                return new Answer(cmd, false, details);
             }
-
             return new Answer(cmd, true, null);
         } else if (dstore instanceof S3TO) {
             final S3TO s3 = (S3TO) dstore;