2121
2222import org .apache .log4j .Logger ;
2323
24- import com .cloud .hypervisor .vmware .util .VmwareContext ;
25- import com .cloud .utils .Pair ;
2624import com .vmware .vim25 .DatastoreSummary ;
2725import com .vmware .vim25 .FileInfo ;
2826import com .vmware .vim25 .HostDatastoreBrowserSearchResults ;
3432import com .vmware .vim25 .SelectionSpec ;
3533import com .vmware .vim25 .TraversalSpec ;
3634
35+ import com .cloud .hypervisor .vmware .util .VmwareContext ;
36+ import com .cloud .utils .Pair ;
37+
3738public 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