@@ -49,12 +49,7 @@ func (VolAPIImplementor) FormatVolume(volumeID string) (err error) {
49
49
50
50
// WriteVolumeCache - Writes the file system cache to disk with the given volume id
51
51
func (VolAPIImplementor ) WriteVolumeCache (volumeID string ) (err error ) {
52
- cmd := fmt .Sprintf ("Get-Volume -UniqueId \" %s\" | Write-Volumecache" , volumeID )
53
- out , err := runExec (cmd )
54
- if err != nil {
55
- return fmt .Errorf ("error writing volume cache. cmd: %s, output: %s, error: %v" , cmd , string (out ), err )
56
- }
57
- return nil
52
+ return writeCache (volumeID )
58
53
}
59
54
60
55
// IsVolumeFormatted - Check if the volume is formatted with the pre specified filesystem(typically ntfs).
@@ -82,6 +77,9 @@ func (VolAPIImplementor) MountVolume(volumeID, path string) error {
82
77
83
78
// DismountVolume - unmounts the volume path by removing the partition access path
84
79
func (VolAPIImplementor ) DismountVolume (volumeID , path string ) error {
80
+ if err := writeCache (volumeID ); err != nil {
81
+ return err
82
+ }
85
83
cmd := fmt .Sprintf ("Get-Volume -UniqueId \" %s\" | Get-Partition | Remove-PartitionAccessPath -AccessPath %s" , volumeID , path )
86
84
out , err := runExec (cmd )
87
85
if err != nil {
@@ -217,3 +215,12 @@ func getTarget(mount string) (string, error) {
217
215
218
216
return volumeString , nil
219
217
}
218
+
219
+ func writeCache (volumeID string ) error {
220
+ cmd := fmt .Sprintf ("Get-Volume -UniqueId \" %s\" | Write-Volumecache" , volumeID )
221
+ out , err := runExec (cmd )
222
+ if err != nil {
223
+ return fmt .Errorf ("error writing volume cache. cmd: %s, output: %s, error: %v" , cmd , string (out ), err )
224
+ }
225
+ return nil
226
+ }
0 commit comments