@@ -87,6 +87,7 @@ func (VolAPIImplementor) ResizeVolume(volumeID string, size int64) error {
87
87
var out []byte
88
88
var err error
89
89
var finalSize int64
90
+ var outString string
90
91
if size == 0 {
91
92
cmd = fmt .Sprintf ("Get-Volume -UniqueId \" %s\" | Get-partition | Get-PartitionSupportedSize | Select SizeMax | ConvertTo-Json" , volumeID )
92
93
out , err = runExec (cmd )
@@ -96,7 +97,7 @@ func (VolAPIImplementor) ResizeVolume(volumeID string, size int64) error {
96
97
}
97
98
98
99
var getVolumeSizing map [string ]int64
99
- outString : = string (out )
100
+ outString = string (out )
100
101
err = json .Unmarshal ([]byte (outString ), & getVolumeSizing )
101
102
if err != nil {
102
103
return fmt .Errorf ("out %v outstring %v err %v" , out , outString , err )
@@ -109,6 +110,27 @@ func (VolAPIImplementor) ResizeVolume(volumeID string, size int64) error {
109
110
finalSize = size
110
111
}
111
112
113
+ cmd = fmt .Sprintf ("Get-Volume -UniqueId \" %s\" | Get-partition | Select Size" , volumeID )
114
+ out , err = runExec (cmd )
115
+
116
+ if err != nil || len (out ) == 0 {
117
+ return fmt .Errorf ("error getting size of the partition from moun. cmd %s, output: %s, error: %v" , cmd , string (out ), err )
118
+ }
119
+
120
+ var getPartitionSizing map [string ]int64
121
+ outString = string (out )
122
+ err = json .Unmarshal ([]byte (outString ), & getPartitionSizing )
123
+ if err != nil {
124
+ return fmt .Errorf ("out %v outstring %v err %v" , out , outString , err )
125
+ }
126
+
127
+ currentSize := getPartitionSizing ["Size" ]
128
+
129
+ //if the partition's size is already the size we want this is a noop, just return
130
+ if currentSize >= finalSize {
131
+ return nil
132
+ }
133
+
112
134
cmd = fmt .Sprintf ("Get-Volume -UniqueId \" %s\" | Get-partition | Resize-Partition -Size %d" , volumeID , finalSize )
113
135
out , err = runExec (cmd )
114
136
if err != nil {
0 commit comments