Skip to content

Commit 15142ab

Browse files
TonitzppCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 89532a4 commit 15142ab

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,19 @@ public String getBackingFileNameIfExists(String volXML) {
4444
Document doc = builder.parse(is);
4545

4646
Element rootElement = doc.getDocumentElement();
47-
Element backingStore = (Element)rootElement.getElementsByTagName("backingStore").item(0);
48-
if (backingStore != null) {
49-
String[] paths = getTagValue("path", backingStore).split("/");
50-
return paths[paths.length-1];
47+
NodeList backingStores = rootElement.getElementsByTagName("backingStore");
48+
if (backingStores.getLength() > 0) {
49+
Element backingStore = (Element) backingStores.item(0);
50+
NodeList pathNodes = backingStore.getElementsByTagName("path");
51+
if (pathNodes.getLength() > 0) {
52+
String path = pathNodes.item(0).getTextContent();
53+
if (path == null || path.trim().isEmpty()) {
54+
return null;
55+
}
56+
path = path.trim();
57+
int lastSlash = path.lastIndexOf('/');
58+
return lastSlash >= 0 ? path.substring(lastSlash + 1) : path;
59+
}
5160
}
5261
} catch (ParserConfigurationException | SAXException | IOException e) {
5362
logger.error(e.toString(), e);

0 commit comments

Comments
 (0)