diff --git a/src/utils/general.js b/src/utils/general.js index 17abb49..79654ac 100644 --- a/src/utils/general.js +++ b/src/utils/general.js @@ -117,6 +117,10 @@ function stripWindowsDriveLetter(path) { return path.replace(/^[a-zA-Z]:/, ""); } +function hasWindowsDriveLetter(path) { + return /^[a-zA-Z]:/i.test(path); +} + /** * transition function to replicate `request` style requests using axios * @@ -253,6 +257,7 @@ module.exports.lockKeysFromRequest = lockKeysFromRequest; module.exports.getLargestNumber = getLargestNumber; module.exports.stringify = stringify; module.exports.stripWindowsDriveLetter = stripWindowsDriveLetter; +module.exports.hasWindowsDriveLetter = hasWindowsDriveLetter; module.exports.axios_request = axios_request; module.exports.default_supported_block_filesystems = default_supported_block_filesystems; diff --git a/src/utils/windows.js b/src/utils/windows.js index d2a969e..c02ceb3 100644 --- a/src/utils/windows.js +++ b/src/utils/windows.js @@ -1,5 +1,5 @@ -const { result } = require("lodash"); const _ = require("lodash"); +const GeneralUtils = require("./general"); const Powershell = require("./powershell").Powershell; /** @@ -757,6 +757,16 @@ class Windows { async UnmountVolume(volumeId, path) { let command; + + // this errors if it does not have a drive letter + if (!GeneralUtils.hasWindowsDriveLetter(path)) { + let item = await this.GetItem(path); + if (!item) { + return; + } + path = item.FullName; + } + command = `Get-Volume -UniqueId \"${volumeId}\" | Get-Partition | Remove-PartitionAccessPath -AccessPath ${path}`; await this.ps.exec(command);