Skip to content

Commit 0afe9b8

Browse files
committed
noop when resize is called and size of partition is >= requested size
1 parent 46d1981 commit 0afe9b8

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

internal/os/volume/api.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (VolAPIImplementor) ResizeVolume(volumeID string, size int64) error {
8787
var out []byte
8888
var err error
8989
var finalSize int64
90+
var outString string
9091
if size == 0 {
9192
cmd = fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-partition | Get-PartitionSupportedSize | Select SizeMax | ConvertTo-Json", volumeID)
9293
out, err = runExec(cmd)
@@ -96,7 +97,7 @@ func (VolAPIImplementor) ResizeVolume(volumeID string, size int64) error {
9697
}
9798

9899
var getVolumeSizing map[string]int64
99-
outString := string(out)
100+
outString = string(out)
100101
err = json.Unmarshal([]byte(outString), &getVolumeSizing)
101102
if err != nil {
102103
return fmt.Errorf("out %v outstring %v err %v", out, outString, err)
@@ -109,6 +110,27 @@ func (VolAPIImplementor) ResizeVolume(volumeID string, size int64) error {
109110
finalSize = size
110111
}
111112

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+
112134
cmd = fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-partition | Resize-Partition -Size %d", volumeID, finalSize)
113135
out, err = runExec(cmd)
114136
if err != nil {

0 commit comments

Comments
 (0)