"use strict"; const Promise = require("bluebird"); const execBinary = require("../../exec-binary"); const { errorResult } = require("../../text-parser"); const createRegexParser = require("../../text-parser-regex"); const handleDeviceNotFound = require("../modifiers/handle-device-not-found"); const handlePhysicalVolumeInUse = require("../modifiers/handle-physical-volume-in-use"); const errors = require("../errors"); module.exports = function ({ devicePath }) { return Promise.try(() => { return execBinary("pvremove", [devicePath]) .asRoot() .requireResult() .withModifier(handleDeviceNotFound(devicePath)) .withModifier(handlePhysicalVolumeInUse(devicePath)) .expectOnStdout(createRegexParser(/Labels on physical volume "[^"]+" successfully wiped\./, () => undefined)) .expectOnStderr(createRegexParser(/No PV( label)? found on .+\./, () => { return errorResult(new errors.InvalidPath(`Specified device '${devicePath}' is not a Physical Volume`, { path: devicePath })); })) .execute(); }).then((_output) => { return true; }); };