diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs index ce1b1e8c6eb..f4d25ecfb6c 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs @@ -160,7 +160,7 @@ namespace HypervResource else { fileName = @"\\" + this.primaryDataStore.uri.Host + this.primaryDataStore.uri.LocalPath + @"\" + this.name; - fileName = fileName.Replace(@"/", @"\"); + fileName = Utils.NormalizePath(fileName); } if (this.format != null) diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs index 7f9e68a84bd..776c0fea158 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs @@ -223,7 +223,7 @@ namespace HypervResource Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password); // The share is mapped, now attach the iso - string isoPath = Path.Combine(share.UncPath.Replace('/', Path.DirectorySeparatorChar), dataStore.path); + string isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path)); wmiCallsV2.AttachIso(vmName, isoPath); result = true; } @@ -267,8 +267,7 @@ namespace HypervResource { NFSTO share = dataStore.nfsDataStoreTO; // The share is mapped, now attach the iso - string isoPath = Path.Combine(share.UncPath.Replace('/', Path.DirectorySeparatorChar), - dataStore.path.Replace('/', Path.DirectorySeparatorChar)); + string isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path)); wmiCallsV2.DetachDisk(vmName, isoPath); result = true; } @@ -957,7 +956,7 @@ namespace HypervResource share.uri = new Uri(uriStr); string defaultDataPath = wmiCallsV2.GetDefaultDataRoot(); - string secondaryPath = Path.Combine(share.UncPath, "systemvm").Replace(@"/", @"\"); + string secondaryPath = Utils.NormalizePath(Path.Combine(share.UncPath, "systemvm")); string[] choices = choices = Directory.GetFiles(secondaryPath, "systemvm*.iso"); if (choices.Length != 1) { @@ -966,7 +965,7 @@ namespace HypervResource } else { - systemVmIsoPath = Path.Combine(defaultDataPath, Path.GetFileName(choices[0])); + systemVmIsoPath = Utils.NormalizePath(Path.Combine(defaultDataPath, Path.GetFileName(choices[0]))); if (!File.Exists(systemVmIsoPath)) { Utils.DownloadCifsFileToLocalFile(choices[0], share, systemVmIsoPath); @@ -1057,7 +1056,7 @@ namespace HypervResource else { volumePath = @"\\" + primary.uri.Host + primary.uri.LocalPath + @"\" + volumeName; - volumePath = volumePath.Replace('/', '\\'); + volumePath = Utils.NormalizePath(volumePath); Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password); } diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs index 0f7505d67d8..c4b39ba24c2 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs @@ -56,6 +56,16 @@ namespace HypervResource return objContent; } + public static string NormalizePath(string path) + { + if (!String.IsNullOrEmpty(path)) + { + path = path.Replace('/', Path.DirectorySeparatorChar); + } + + return path; + } + /// /// Copy file on network share to local volume. /// @@ -80,7 +90,7 @@ namespace HypervResource if (filePathRelativeToShare.EndsWith(".iso") || filePathRelativeToShare.EndsWith(".vhd") || filePathRelativeToShare.EndsWith(".vhdx")) { dest = Path.Combine(cifsShareDetails.UncPath, filePathRelativeToShare); - dest = dest.Replace('/', Path.DirectorySeparatorChar); + dest = Utils.NormalizePath(dest); } // if the filePathRelativeToShare string don't have filename and only a dir point then find the vhd files in that folder and use // In the clean setup, first copy command wont be having the filename it contains onlyu dir path. @@ -117,7 +127,7 @@ namespace HypervResource { NETRESOURCE nr = new NETRESOURCE(); nr.dwType = RESOURCETYPE_DISK; - nr.lpRemoteName = remoteUNC.Replace('/', Path.DirectorySeparatorChar); + nr.lpRemoteName = Utils.NormalizePath(remoteUNC); if (domain != null) { username = domain + @"\" + username; diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs index b2feab35ddd..c89f837a7a6 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs @@ -335,7 +335,7 @@ namespace HypervResource NFSTO share = templateInfo.nfsDataStoreTO; Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password); // The share is mapped, now attach the iso - isoPath = Path.Combine(share.UncPath.Replace('/', Path.DirectorySeparatorChar), templateInfo.path); + isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, templateInfo.path)); } string driveType = diskDrive.type;