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:36:07 UTC
git commit: updated refs/heads/4.2 to 5889717
Updated Branches:
refs/heads/4.2 ea7f66c36 -> 5889717d9
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/5889717d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5889717d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5889717d
Branch: refs/heads/4.2
Commit: 5889717d9a7e1366380bcaa5bff7729c4c92a9e8
Parents: ea7f66c
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:30:12 2013 -0700
----------------------------------------------------------------------
.../resource/NfsSecondaryStorageResource.java | 35 +++++++++++---------
1 file changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5889717d/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;