Skip to content

Commit

Permalink
fix vss stale snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 4, 2024
1 parent 210ffe9 commit bee4f44
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions internal/agent/snapshots/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ func Snapshot(driveLetter string) (*WinVSSSnapshot, error) {
err = vss.CreateLink(snapshotPath, volName)
if err != nil {
if strings.Contains(err.Error(), "already exists") {
if KnownSnapshots != nil {
for _, knownSnap := range KnownSnapshots {
if knownSnap.SnapshotPath == snapshotPath && time.Since(knownSnap.LastAccessed) < time.Hour {
return knownSnap, nil
if _, err := vss.Get(snapshotPath); err == nil {
if KnownSnapshots != nil {
for _, knownSnap := range KnownSnapshots {
if knownSnap.SnapshotPath == snapshotPath && time.Since(knownSnap.LastAccessed) < time.Hour {
return knownSnap, nil
} else {
knownSnap.Close()
break
}
}
}
}
if _, err := vss.Get(snapshotPath); err == nil {
_ = vss.Remove(snapshotPath)
}

_ = os.Remove(snapshotPath)

if err := vss.CreateLink(snapshotPath, volName); err != nil {
Expand Down Expand Up @@ -89,11 +92,8 @@ func Snapshot(driveLetter string) (*WinVSSSnapshot, error) {
return &newSnapshot, nil
}

func (instance *WinVSSSnapshot) Close() error {
err := vss.Remove(instance.Id)
if err != nil {
return fmt.Errorf("Close: error deleting snapshot %s -> %w", instance.SnapshotPath, err)
}
func (instance *WinVSSSnapshot) Close() {
_ = vss.Remove(instance.Id)

if KnownSnapshots != nil {
newKnownSnapshots := []*WinVSSSnapshot{}
Expand All @@ -106,13 +106,13 @@ func (instance *WinVSSSnapshot) Close() error {
KnownSnapshots = newKnownSnapshots
}

return nil
return
}

func CloseAllSnapshots() {
if KnownSnapshots != nil {
for _, snapshot := range KnownSnapshots {
_ = snapshot.Close()
snapshot.Close()
}
}
}

0 comments on commit bee4f44

Please sign in to comment.