diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c5354a..58c60c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [6.14.1] - 2024-05-28 +### Fixed +- Fixed #185 - location.Exists was checking if a list entry was a directory but it was was only checking the first entry. + ## [6.14.0] - 2024-05-15 ### Security - updated dependencies diff --git a/backend/ftp/file.go b/backend/ftp/file.go index cfc0647d..92eaa451 100644 --- a/backend/ftp/file.go +++ b/backend/ftp/file.go @@ -195,7 +195,7 @@ func (f *File) MoveToFile(t vfs.File) error { // it doesn't matter which client we use since they are effectively the same err = dc.MakeDir(t.Location().Path()) if err != nil { - return err + return fmt.Errorf("failed to create directory: %w", err) } } return dc.Rename(f.Path(), t.Path()) diff --git a/backend/ftp/location.go b/backend/ftp/location.go index 130ff3e4..2e1ec0ef 100644 --- a/backend/ftp/location.go +++ b/backend/ftp/location.go @@ -144,8 +144,9 @@ func (l *Location) Exists() (bool, error) { return false, err } + locBasename := path.Base(l.Path()) // get parent directory by removing the last part of the path - parentDir := strings.TrimSuffix(l.Path(), path.Base(l.Path())+"/") + parentDir := strings.TrimSuffix(l.Path(), locBasename+"/") entries, err := dc.List(parentDir) if err != nil { @@ -156,8 +157,8 @@ func (l *Location) Exists() (bool, error) { return false, err } - for _, entry := range entries { - if entry.Name == path.Base(l.Path()) && entries[0].Type == _ftp.EntryTypeFolder { + for i := range entries { + if entries[i].Name == locBasename && entries[i].Type == _ftp.EntryTypeFolder { return true, nil } } diff --git a/backend/ftp/location_test.go b/backend/ftp/location_test.go index 50730a62..1c9f8df1 100644 --- a/backend/ftp/location_test.go +++ b/backend/ftp/location_test.go @@ -388,7 +388,13 @@ func (lt *locationTestSuite) TestExists() { // location exists locPath := "/" - dirs := []*_ftp.Entry{ + entries := []*_ftp.Entry{ + { + Name: "file.txt", + Target: "", + Type: _ftp.EntryTypeFile, + Time: time.Now().UTC(), + }, { Name: locPath, Target: "", @@ -396,7 +402,7 @@ func (lt *locationTestSuite) TestExists() { Time: time.Now().UTC(), }, } - lt.client.On("List", locPath).Return(dirs, nil).Once() + lt.client.On("List", locPath).Return(entries, nil).Once() loc, err := lt.ftpfs.NewLocation(authority, locPath) lt.NoError(err) exists, err := loc.Exists() @@ -405,8 +411,15 @@ func (lt *locationTestSuite) TestExists() { // locations does not exist locPath = "/my/dir/" - dirs = []*_ftp.Entry{} - lt.client.On("List", "/my/").Return(dirs, nil).Once() + entries = []*_ftp.Entry{ + { + Name: "file.txt", + Target: "", + Type: _ftp.EntryTypeFile, + Time: time.Now().UTC(), + }, + } + lt.client.On("List", "/my/").Return(entries, nil).Once() loc, err = lt.ftpfs.NewLocation(authority, locPath) lt.NoError(err) exists, err = loc.Exists() @@ -414,15 +427,21 @@ func (lt *locationTestSuite) TestExists() { lt.True(!exists, "Call to Exists expected to return false.") // some error calling list - lt.client.On("List", "/my/").Return(dirs, errors.New("some error")).Once() + lt.client.On("List", "/my/").Return(entries, errors.New("some error")).Once() loc, err = lt.ftpfs.NewLocation(authority, locPath) lt.NoError(err) exists, err = loc.Exists() lt.Error(err, "from Exists") lt.True(!exists, "Call to Exists expected to return false.") - // check for not dir -- this shoudln't be possible since NewLocation won't accept non-absolute directories - dirs = []*_ftp.Entry{ + // check for not dir -- this shouldn't be possible since NewLocation won't accept non-absolute directories + entries = []*_ftp.Entry{ + { + Name: "file.txt", + Target: "", + Type: _ftp.EntryTypeFile, + Time: time.Now().UTC(), + }, { Name: locPath, Target: "", @@ -430,7 +449,7 @@ func (lt *locationTestSuite) TestExists() { Time: time.Now().UTC(), }, } - lt.client.On("List", "/my/").Return(dirs, nil).Once() + lt.client.On("List", "/my/").Return(entries, nil).Once() loc, err = lt.ftpfs.NewLocation(authority, locPath) lt.NoError(err) exists, err = loc.Exists()