Skip to content

Commit

Permalink
delete snapshot path after close or error
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 13, 2024
1 parent e113d27 commit fd54bc5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/agent/snapshots/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func Snapshot(driveLetter string) (*WinVSSSnapshot, error) {
}
knownSnap.Close()
_ = vss.Remove(snapshotPath) // Clean up old snapshot link if expired
_ = os.Remove(snapshotPath)
}

// Attempt to create a new snapshot
Expand All @@ -57,6 +58,7 @@ func Snapshot(driveLetter string) (*WinVSSSnapshot, error) {
}
} else if strings.Contains(err.Error(), "already exists") {
_ = vss.Remove(snapshotPath)
_ = os.Remove(snapshotPath)
err = vss.CreateLink(snapshotPath, volName)
if err != nil {
return nil, fmt.Errorf("Snapshot: error creating snapshot (%s to %s) -> %w", volName, snapshotPath, err)
Expand All @@ -70,6 +72,7 @@ func Snapshot(driveLetter string) (*WinVSSSnapshot, error) {
sc, err := vss.Get(snapshotPath)
if err != nil {
_ = vss.Remove(snapshotPath)
_ = os.Remove(snapshotPath)
return nil, fmt.Errorf("Snapshot: error getting snapshot details -> %w", err)
}

Expand Down Expand Up @@ -111,6 +114,7 @@ func (instance *WinVSSSnapshot) UpdateTimestamp() {

func (instance *WinVSSSnapshot) Close() {
_ = vss.Remove(instance.Id)
_ = os.Remove(instance.SnapshotPath)

knownSnaps := &KnownSnapshots{
registry: "KnownSnaps",
Expand Down

0 comments on commit fd54bc5

Please sign in to comment.