Skip to content

Commit

Permalink
tf2vpk: ValvePakRef.Delete -> ValvePakRef.List
Browse files Browse the repository at this point in the history
  • Loading branch information
pg9182 committed Apr 14, 2024
1 parent b455de4 commit 19fd2cc
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions fs.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package tf2vpk

import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -92,7 +90,7 @@ func (v ValvePakRef) Resolve(i ValvePakIndex) string {
return filepath.Join(v.Path, fn)
}

func (v ValvePakRef) Delete() error {
func (v ValvePakRef) List() ([]string, error) {
if v.Path == "" {
v.Path = "."
}
Expand All @@ -101,30 +99,14 @@ func (v ValvePakRef) Delete() error {
}
ds, err := os.ReadDir(v.Path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
err = nil
}
return err
return nil, err
}

var errs []error
var ns []string
for _, d := range ds {
// ensure it's a vpk file belonging to us
name, _, err := SplitName(d.Name(), v.Prefix)
if err != nil || name != v.Name {
continue
if name, _, err := SplitName(d.Name(), v.Prefix); err == nil && name == v.Name {
ns = append(ns, d.Name())
}

// try and remove it
if err := os.Remove(filepath.Join(v.Path, d.Name())); err != nil {
if errors.Is(err, fs.ErrNotExist) {
err = nil
}
errs = append(errs, err)
}
}
if err := errors.Join(errs...); err != nil {
return fmt.Errorf("delete vpk: %w", err)
}
return nil
return ns, nil
}

0 comments on commit 19fd2cc

Please sign in to comment.