Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add writevolumecache into Dismount API #92

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions internal/os/volume/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ func (VolAPIImplementor) FormatVolume(volumeID string) (err error) {

// WriteVolumeCache - Writes the file system cache to disk with the given volume id
func (VolAPIImplementor) WriteVolumeCache(volumeID string) (err error) {
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Write-Volumecache", volumeID)
out, err := runExec(cmd)
if err != nil {
return fmt.Errorf("error writing volume cache. cmd: %s, output: %s, error: %v", cmd, string(out), err)
}
return nil
return writeCache(volumeID)
}

// IsVolumeFormatted - Check if the volume is formatted with the pre specified filesystem(typically ntfs).
Expand Down Expand Up @@ -82,6 +77,9 @@ func (VolAPIImplementor) MountVolume(volumeID, path string) error {

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

return volumeString, nil
}

func writeCache(volumeID string) error {
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Write-Volumecache", volumeID)
out, err := runExec(cmd)
if err != nil {
return fmt.Errorf("error writing volume cache. cmd: %s, output: %s, error: %v", cmd, string(out), err)
}
return nil
}