corrected archivefs Set() function so that it works in Windows

Windows volume names confused the Set() function

archivefs.Async no longer exits async goroutine on errors from Path
functions. exiting meant that the channels were no longer being
serviced, causing GUI deadlocks
This commit is contained in:
JetSetIlly 2024-05-05 14:38:15 +01:00
parent 6c96b2f065
commit 7be60c0c2a
2 changed files with 19 additions and 3 deletions

View file

@ -68,12 +68,16 @@ func NewAsyncPath(setter FilenameSetter) AsyncPath {
afs.Close()
case path := <-pth.Set:
afs.Set(path)
err := afs.Set(path)
if err != nil {
pth.err <- err
continue // for loop
}
entries, err := afs.List()
if err != nil {
pth.err <- err
return
continue // for loop
}
pth.results <- AsyncResults{

View file

@ -223,8 +223,12 @@ func (afs *Path) List() ([]Node, error) {
func (afs *Path) Set(path string) error {
afs.Close()
// clean path and split into parts
// clean path and and remove volume name. volume name is not something we
// typically have to worry about in unix type systems
path = filepath.Clean(path)
path = strings.TrimPrefix(path, filepath.VolumeName(path))
// split path into parts
lst := strings.Split(path, string(filepath.Separator))
// strings.Split will remove a leading filepath.Separator. we need to add
@ -284,6 +288,14 @@ func (afs *Path) Set(path string) error {
}
}
// we want the absolute path. this restores any volume name that may have
// been trimmed off at the start of the function
var err error
afs.current, err = filepath.Abs(path)
if err != nil {
return fmt.Errorf("archivefs: set: %v", err)
}
// make sure path is clean
afs.current = filepath.Clean(path)