Skip to content

Commit 3b92646

Browse files
authored
Merge pull request #92 from jingxu97/oct/dismount
Add writevolumecache into Dismount API
2 parents b3cbf0c + 813c7bc commit 3b92646

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

internal/os/volume/api.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ func (VolAPIImplementor) FormatVolume(volumeID string) (err error) {
4949

5050
// WriteVolumeCache - Writes the file system cache to disk with the given volume id
5151
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)
5853
}
5954

6055
// 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 {
8277

8378
// DismountVolume - unmounts the volume path by removing the partition access path
8479
func (VolAPIImplementor) DismountVolume(volumeID, path string) error {
80+
if err := writeCache(volumeID); err != nil {
81+
return err
82+
}
8583
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-Partition | Remove-PartitionAccessPath -AccessPath %s", volumeID, path)
8684
out, err := runExec(cmd)
8785
if err != nil {
@@ -217,3 +215,12 @@ func getTarget(mount string) (string, error) {
217215

218216
return volumeString, nil
219217
}
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

Comments
 (0)