Support recursive directory uploads
All checks were successful
Build / Test and build (push) Successful in 5m41s

This commit is contained in:
2026-08-14 23:47:54 +08:00
parent c2eecdebbb
commit c1758cf29c
6 changed files with 355 additions and 6 deletions

View File

@@ -66,6 +66,38 @@ func (c *Client) Mkdir(ctx context.Context, name string) (File, error) {
return result, nil
}
func (c *Client) MkdirAll(ctx context.Context, name string) error {
target := path.Clean("/" + strings.TrimPrefix(name, "/"))
if target == "/" {
return nil
}
current := "/"
for _, component := range strings.Split(strings.TrimPrefix(target, "/"), "/") {
current = path.Join(current, component)
if err := c.EnsureDirectory(ctx, current); err != nil {
return err
}
}
return nil
}
func (c *Client) EnsureDirectory(ctx context.Context, name string) error {
entry, err := c.Stat(ctx, name)
if err == nil {
if !entry.IsDirectory() {
return fmt.Errorf("remote path exists and is not a directory: %s", name)
}
return nil
}
if !errors.Is(err, ErrNotFound) {
return fmt.Errorf("check remote directory %s: %w", name, err)
}
if _, err := c.Mkdir(ctx, name); err != nil {
return fmt.Errorf("create remote directory %s: %w", name, err)
}
return nil
}
func (c *Client) Delete(ctx context.Context, name string) error {
remote := c.RemotePath(name)
if remote == c.root {