Skip to content

Commit

Permalink
use own max and min
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol authored Feb 21, 2025
1 parent b23e1b9 commit 106a9f2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions internal/vss/vss.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
package vss

import (
"fmt"
"math"
"os"
"path/filepath"
"strings"
Expand All @@ -22,6 +20,22 @@ import (
"golang.org/x/sys/windows"
)

// Min returns the smaller of a and b.
func Min[T constraints.Ordered](a, b T) T {
if a < b {
return a
}
return b
}

// Max returns the larger of a and b.
func Max[T constraints.Ordered](a, b T) T {
if a > b {
return a
}
return b
}

// errNotAdmin is returned when the current user lacks admin privileges.
var errNotAdmin = fmt.Errorf("vss: do not have Administrators group privileges (%w)",
os.ErrPermission)
Expand Down Expand Up @@ -109,7 +123,7 @@ func SplitVolume(name string) (vol, rel string, err error) {
// relative paths.
return "", "", fmt.Errorf("vss: non-absolute path: %s", name)
}
buf := make([]uint16, math.Max(len(name), syscall.MAX_PATH))
buf := make([]uint16, Max(len(name), syscall.MAX_PATH))
if err = windows.GetVolumePathName(utf16Ptr(name), &buf[0], uint32(len(buf))); err != nil {
return "", "", fmt.Errorf("vss: GetVolumePathName failed for: %s (%w)", name, err)
}
Expand Down Expand Up @@ -427,7 +441,7 @@ func volumePaths(vol string) ([]string, error) {
i++
}
all = append(all, syscall.UTF16ToString(b[:i]))
b = b[math.Min(i+1, len(b)):]
b = b[Min(i+1, len(b)):]
}
return all, nil
}
Expand Down

0 comments on commit 106a9f2

Please sign in to comment.