Skip to content

Commit bbd7183

Browse files
author
Sateesh Chodapuneedi
committed
CLOUDSTACK-3529 Unable to test file existence due to exception java.lang.RuntimeException
See if file being deleted is directory or file. Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>
1 parent ea3a77e commit bbd7183

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

vmware-base/src/com/cloud/hypervisor/vmware/mo/DatastoreMO.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import org.apache.log4j.Logger;
2323

24-
import com.cloud.hypervisor.vmware.util.VmwareContext;
25-
import com.cloud.utils.Pair;
2624
import com.vmware.vim25.DatastoreSummary;
2725
import com.vmware.vim25.FileInfo;
2826
import com.vmware.vim25.HostDatastoreBrowserSearchResults;
@@ -34,6 +32,9 @@
3432
import com.vmware.vim25.SelectionSpec;
3533
import com.vmware.vim25.TraversalSpec;
3634

35+
import com.cloud.hypervisor.vmware.util.VmwareContext;
36+
import com.cloud.utils.Pair;
37+
3738
public class DatastoreMO extends BaseMO {
3839
private static final Logger s_logger = Logger.getLogger(DatastoreMO.class);
3940

@@ -48,7 +49,8 @@ public DatastoreMO(VmwareContext context, String morType, String morValue) {
4849
super(context, morType, morValue);
4950
}
5051

51-
public String getName() throws Exception {
52+
@Override
53+
public String getName() throws Exception {
5254
if(_name == null)
5355
_name = (String)_context.getVimClient().getDynamicProperty(_mor, "name");
5456

@@ -131,10 +133,15 @@ public boolean deleteFile(String path, ManagedObjectReference morDc, boolean tes
131133
String fullPath = path;
132134
if(!DatastoreFile.isFullDatastorePath(fullPath))
133135
fullPath = String.format("[%s] %s", datastoreName, path);
136+
DatastoreFile file = new DatastoreFile(fullPath);
137+
// Test if file specified is null or empty. We don't need to attempt to delete and return success.
138+
if (file.getFileName() == null || file.getFileName().isEmpty()) {
139+
return true;
140+
}
134141

135142
try {
136143
if(testExistence && !fileExists(fullPath)) {
137-
String searchResult = searchFileInSubFolders(fullPath.split(" ")[1], true);
144+
String searchResult = searchFileInSubFolders(file.getFileName(), true);
138145
if (searchResult == null) {
139146
return true;
140147
} else {

0 commit comments

Comments
 (0)