Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,16 @@ private void savePostUploadPSK(String psk) {
}
}

protected String getSnapshotFilepathForDelete(String path, String snapshotName) {
if (!path.endsWith(snapshotName)) {
return path + "/*" + snapshotName + "*";
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Snapshot file %s is present in the same name directory %s. Deleting the directory", snapshotName, path));
}
return path;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shwstppr
would it be safer to check if the path is a directory and there is no files in the directory before deletion ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weizhouapache directory check be added but we always expect it to be a directory anyway as we append the `/SNAPSHOT_NAME

And there will always be files (I checked VMware, Xen and KVM. Snapshots are placed inside the same name folder only for VMWare). Example

[root@sl-nestednfs snapshots]# tree 2/10/
2/10/
└── fd57cb44-0559-490c-998d-5313eec52cef
    ├── fd57cb44-0559-490c-998d-5313eec52cef-disk0.vmdk
    ├── fd57cb44-0559-490c-998d-5313eec52cef-disk1.nvram
    └── fd57cb44-0559-490c-998d-5313eec52cef.ovf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we need to cover both cases, to check if we're deleting files inside a folder (like in vmware), but also for kvm where snapshots arne't in a folder. XenServer/XCP-ng we need to check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weizhouapache @shwstppr , we are dealing with a String, not a File/directory. I think this is ok, in this place. checking for existence should not happen in this method.


protected Answer deleteSnapshot(final DeleteCommand cmd) {
DataTO obj = cmd.getData();
DataStoreTO dstore = obj.getDataStore();
Expand Down Expand Up @@ -2033,7 +2043,7 @@ protected Answer deleteSnapshot(final DeleteCommand cmd) {
return new Answer(cmd, true, details);
}
// delete snapshot in the directory if exists
String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
String lPath = getSnapshotFilepathForDelete(absoluteSnapshotPath, snapshotName);
String result = deleteLocalFile(lPath);
if (result != null) {
details = "failed to delete snapshot " + lPath + " , err=" + result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,21 @@ public void testCleanupStagingNfs() throws Exception{
testLogAppender.assertMessagesLogged();

}

private void performGetSnapshotFilepathForDeleteTest(String expected, String path, String name) {
Assert.assertEquals("Incorrect resultant snapshot delete path", expected, resource.getSnapshotFilepathForDelete(path, name));
}

@Test
public void testGetSnapshotFilepathForDelete() {
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/somename",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"/snapshots/2/10/somename",
"somename");
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/diffName/*diffname*",
"/snapshots/2/10/diffName",
"diffname");
performGetSnapshotFilepathForDeleteTest("/snapshots/2/10/*somename*",
"/snapshots/2/10",
"somename");
}
}