Support recursive directory uploads
All checks were successful
Build / Test and build (push) Successful in 5m41s
All checks were successful
Build / Test and build (push) Successful in 5m41s
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user