Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cmd/mkdir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
"context"
"strings"

"github.com/spf13/cobra"
)

func init() {
cmd := &cobra.Command{
Use: "mkdir rpath",
Short: "Create an empty remote directory.",
Example: strings.TrimSpace(`
# Create an empty directory
datasafed mkdir some/dir
`),
Args: cobra.ExactArgs(1),
Run: doMkdir,
}
rootCmd.AddCommand(cmd)
}

func doMkdir(cmd *cobra.Command, args []string) {
err := globalStorage.Mkdir(context.Background(), args[0])
exitIfError(err)
}
5 changes: 5 additions & 0 deletions pkg/storage/rclone/rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func (s *rcloneStorage) Rmdir(ctx context.Context, rpath string) error {
return s.f.Rmdir(ctx, rpath)
}

func (s *rcloneStorage) Mkdir(ctx context.Context, rpath string) error {
rpath = normalizeRemotePath(rpath)
return s.f.Mkdir(ctx, rpath)
}

func (s *rcloneStorage) list(ctx context.Context, rpath string, opt *storage.ListOptions, callback func(item *operations.ListJSONItem) error) error {
ljOpt := &operations.ListJSONOpt{}
if opt != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/storage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type Storage interface {
// Rmdir removes the directory in the given path only if the directory is empty.
Rmdir(ctx context.Context, rpath string) error

// Mkdir makes a directory.
Mkdir(ctx context.Context, rpath string) error

// List lists the contents of the given path.
// The `rpath` parameter can also be a file, in this case the function
// will return a list with a single entry.
Expand Down