Skip to content

Commit

Permalink
Merge pull request #130 from PlagueHO/Issue-103
Browse files Browse the repository at this point in the history
Fix when max size used and disk partitioned and formatted but not mounted - Fixes #103
  • Loading branch information
PlagueHO committed Dec 11, 2017
2 parents 006cab5 + d98d0dd commit 154becc
Show file tree
Hide file tree
Showing 11 changed files with 1,260 additions and 720 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,16 @@

## Unreleased

- xDisk:
- Removed duplicate integration tests for Guid Disk Id type.
- Added new contexts to integration tests improve clarity.
- Fix bug when size not specified and disk partitioned and
formatted but not assigned drive letter - See [Issue 103](https://github.com/PowerShell/xStorage/issues/103).
- xDiskAccessPath:
- Added new contexts to integration tests improve clarity.
- Fix bug when size not specified and disk partitioned and
formatted but not assigned to path - See [Issue 103](https://github.com/PowerShell/xStorage/issues/103).

## 3.3.0.0

- Opted into common tests for Module and Script files - See [Issue 115](https://github.com/PowerShell/xStorage/issues/115).
Expand Down
47 changes: 42 additions & 5 deletions Modules/xStorage/DSCResources/MSFT_xDisk/MSFT_xDisk.psm1
Expand Up @@ -66,7 +66,7 @@ function Get-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number','UniqueId','Guid')]
[ValidateSet('Number', 'UniqueId', 'Guid')]
[System.String]
$DiskIdType = 'Number',

Expand Down Expand Up @@ -184,7 +184,7 @@ function Set-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number','UniqueId','Guid')]
[ValidateSet('Number', 'UniqueId', 'Guid')]
[System.String]
$DiskIdType = 'Number',

Expand Down Expand Up @@ -329,7 +329,7 @@ function Set-TargetResource
{
# Find the first basic partition matching the size
$partition = $partition |
Where-Object -Filter { $_.Type -eq 'Basic' -and $_.Size -eq $Size } |
Where-Object -FilterScript { $_.Type -eq 'Basic' -and $_.Size -eq $Size } |
Select-Object -First 1

if ($partition)
Expand All @@ -347,8 +347,45 @@ function Set-TargetResource
}
else
{
# No size specified so no partition can be matched
<#
No size specified, so see if there is a partition that has a volume
matching the file system type that is not assigned to a drive letter.
#>
Write-Verbose -Message ($localizedData.MatchingPartitionNoSizeMessage -f `
$DiskIdType, $DiskId)

$searchPartitions = $partition | Where-Object -FilterScript {
$_.Type -eq 'Basic' -and -not [System.Char]::IsLetter($_.DriveLetter)
}

$partition = $null

foreach ($searchPartition in $searchPartitions)
{
# Look for the volume in the partition.
Write-Verbose -Message ($localizedData.SearchForVolumeMessage -f `
$DiskIdType, $DiskId, $searchPartition.PartitionNumber, $FSFormat)

$searchVolumes = $searchPartition | Get-Volume

$volumeMatch = $searchVolumes | Where-Object -FilterScript {
$_.FileSystem -eq $FSFormat
}

if ($volumeMatch)
{
<#
Found a partition with a volume that matches file system
type and not assigned a drive letter.
#>
$partition = $searchPartition

Write-Verbose -Message ($localizedData.VolumeFoundMessage -f `
$DiskIdType, $DiskId, $searchPartition.PartitionNumber, $FSFormat)

break
} # if
} # foreach
} # if
} # if

Expand Down Expand Up @@ -612,7 +649,7 @@ function Test-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number','UniqueId','Guid')]
[ValidateSet('Number', 'UniqueId', 'Guid')]
[System.String]
$DiskIdType = 'Number',

Expand Down
Expand Up @@ -26,6 +26,9 @@
DriveLabelMismatch = Volume assigned to drive {0} label '{1}' does not match expected label '{2}'.
PartitionAlreadyAssignedMessage = Partition '{1}' is already assigned as drive {0}.
MatchingPartitionNotFoundMessage = Disk with {0} '{1}' already contains partitions, but none match required size.
MatchingPartitionNoSizeMessage = Disk with {0} '{1}' already contains partitions, but size parameter is not specified.
SearchForVolumeMessage = Searching for {3} volume with no drive letter on partition '{2}' disk with {0} '{1}'.
VolumeFoundMessage = Found {3} volume with no drive letter on partition '{2}' disk with {0} '{1}'.
MatchingPartitionFoundMessage = Disk with {0} '{1}' already contains partitions, and partition '{2}' matches required size.
DriveNotFoundOnPartitionMessage = Disk with {0} '{1}' does not contain a partition assigned to drive letter '{2}'.
ClearingDisk = Clearing disk with {0} '{1}' of all existing partitions and volumes.
Expand Down

0 comments on commit 154becc

Please sign in to comment.