Skip to content

Commit

Permalink
fix(ftp): avoid unnecessary GetEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Jun 29, 2024
1 parent 8f2119c commit a86b16f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/filesystem/ftp/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package ftp

import (
"context"
"os"
"path"
"strings"

"github.com/jlaffaye/ftp"
"github.com/octohelm/unifs/pkg/filesystem"
"github.com/pkg/errors"
"golang.org/x/net/webdav"
"os"
"path"
"strings"
)

func NewFS(c *Config) filesystem.FileSystem {
Expand All @@ -34,16 +33,18 @@ func (f *fs) OpenFile(ctx context.Context, name string, flag int, perm os.FileMo
}
defer c.Close()

// ensure parent exists
if strings.Contains(name, "/") {
_, err := c.GetEntry(path.Dir(name))
if err != nil {
return nil, normalizeError("openfile", name, err)
createWhenNotExists := flag&os.O_CREATE != 0

if createWhenNotExists {
// ensure parent exists
if strings.Contains(name, "/") {
_, err := c.GetEntry(path.Dir(name))
if err != nil {
return nil, normalizeError("openfile", name, err)
}
}
}

createWhenNotExists := flag&os.O_CREATE != 0

ftpEntry, err := c.GetEntry(name)
if err != nil {
e := normalizeError("openfile", name, err)
Expand Down

0 comments on commit a86b16f

Please sign in to comment.