From 7be60c0c2a7a9345c811580059f09d41a1f6eba8 Mon Sep 17 00:00:00 2001 From: JetSetIlly Date: Sun, 5 May 2024 14:38:15 +0100 Subject: [PATCH] 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 --- archivefs/async.go | 8 ++++++-- archivefs/path.go | 14 +++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/archivefs/async.go b/archivefs/async.go index b7cbd572..be020cef 100644 --- a/archivefs/async.go +++ b/archivefs/async.go @@ -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{ diff --git a/archivefs/path.go b/archivefs/path.go index 39164923..3385b3b6 100644 --- a/archivefs/path.go +++ b/archivefs/path.go @@ -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)