Skip to content

Commit

Permalink
touch by id implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed May 17, 2015
1 parent 78d65ed commit 0c0e98c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
30 changes: 14 additions & 16 deletions cmd/drive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ func (cmd *pushCmd) Run(args []string) {
}

type touchCmd struct {
byId *bool
hidden *bool
recursive *bool
matches *bool
Expand All @@ -412,28 +413,25 @@ func (cmd *touchCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
cmd.recursive = fs.Bool("r", false, "toggles recursive touching")
cmd.matches = fs.Bool("matches", false, "search by prefix and touch")
cmd.quiet = fs.Bool(drive.QuietKey, false, "if set, do not log anything but errors")
cmd.byId = fs.Bool(drive.CLIOptionId, false, "share by id instead of path")
return fs
}

func (cmd *touchCmd) Run(args []string) {
sources, context, path := preprocessArgsByToggle(args, *cmd.matches || *cmd.byId)

opts := drive.Options{
Hidden: *cmd.hidden,
Path: path,
Recursive: *cmd.recursive,
Sources: sources,
Quiet: *cmd.quiet,
}

if *cmd.matches {
cwd, err := os.Getwd()
exitWithError(err)
_, context, path := preprocessArgs([]string{cwd})
exitWithError(drive.New(context, &drive.Options{
Path: path,
Sources: args,
Quiet: *cmd.quiet,
}).TouchByMatch())
exitWithError(drive.New(context, &opts).TouchByMatch())
} else {
sources, context, path := preprocessArgs(args)
exitWithError(drive.New(context, &drive.Options{
Hidden: *cmd.hidden,
Path: path,
Recursive: *cmd.recursive,
Sources: sources,
Quiet: *cmd.quiet,
}).Touch())
exitWithError(drive.New(context, &opts).Touch(*cmd.byId))
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ import (
"time"
)

func (g *Commands) Touch() (err error) {
func (g *Commands) Touch(byId bool) (err error) {
// Arbitrary value for rate limiter
throttle := time.Tick(1e9 / 10)

chanMap := map[int]chan *keyValue{}

for i, relToRootPath := range g.opts.Sources {
chanMap[i] = g.touch(relToRootPath, "")
fileId := ""
if byId {
fileId = relToRootPath
}
chanMap[i] = g.touch(relToRootPath, fileId)
<-throttle
}

Expand Down

0 comments on commit 0c0e98c

Please sign in to comment.