mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-2497: Object_Store_Refactor - Snapshots - Not able to delete
snapshots.
This commit is contained in:
parent
1b4900a8a9
commit
9f019ec7c3
@ -1269,30 +1269,35 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||||||
DataStoreTO dstore = obj.getDataStore();
|
DataStoreTO dstore = obj.getDataStore();
|
||||||
if (dstore instanceof NfsTO) {
|
if (dstore instanceof NfsTO) {
|
||||||
NfsTO nfs = (NfsTO) dstore;
|
NfsTO nfs = (NfsTO) dstore;
|
||||||
String relativeSnapshotPath = obj.getPath();
|
String snapshotPath = obj.getPath();
|
||||||
String parent = getRootDir(nfs.getUrl());
|
if (snapshotPath.startsWith(File.separator)) {
|
||||||
|
snapshotPath = snapshotPath.substring(1);
|
||||||
if (relativeSnapshotPath.startsWith(File.separator)) {
|
|
||||||
relativeSnapshotPath = relativeSnapshotPath.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)) {
|
if (!parent.endsWith(File.separator)) {
|
||||||
parent += File.separator;
|
parent += File.separator;
|
||||||
}
|
}
|
||||||
String absoluteSnapshotPath = parent + relativeSnapshotPath;
|
String absoluteSnapshotPath = parent + snapshotPath;
|
||||||
File snapshot = new File(absoluteSnapshotPath);
|
// check if directory exists
|
||||||
|
File snapshotDir = new File(absoluteSnapshotPath);
|
||||||
String details = null;
|
String details = null;
|
||||||
if (!snapshot.exists()) {
|
if (!snapshotDir.exists()) {
|
||||||
details = "snapshot file " + snapshot.getName() + " doesn't exist";
|
details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
|
||||||
s_logger.debug(details);
|
s_logger.debug(details);
|
||||||
return new Answer(cmd, true, details);
|
return new Answer(cmd, false, details);
|
||||||
}
|
}
|
||||||
|
// delete snapshot in the directory if exists
|
||||||
if (!snapshot.delete()) {
|
String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
|
||||||
return new Answer(cmd, false, "Unable to delete file " + snapshot.getName() + " under install path "
|
String result = deleteLocalFile(lPath);
|
||||||
+ relativeSnapshotPath);
|
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);
|
return new Answer(cmd, true, null);
|
||||||
} else if (dstore instanceof S3TO) {
|
} else if (dstore instanceof S3TO) {
|
||||||
final S3TO s3 = (S3TO) dstore;
|
final S3TO s3 = (S3TO) dstore;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user