Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch traversal depth #482

Merged
merged 2 commits into from
Nov 17, 2015
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ $ drive touch -matches $(seq 0 9)
$ drive touch --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
```

+ You can also touch files to a desired depth of nesting within their parent folders.

```shell
$ drive touch --depth 3 mnt newest flux
$ drive touch --depth -1 --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
$ drive touch --depth 1 --matches $(seq 0 9)
```

### Trashing and Untrashing

Files can be trashed using the `trash` command:
Expand Down
12 changes: 12 additions & 0 deletions cmd/drive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,12 @@ func (qCmd *qrLinkCmd) Run(args []string, definedFlags map[string]*flag.Flag) {

type touchCmd struct {
ById *bool `json:"by-id"`
Depth *int `json:"depth"`
Hidden *bool `json:"hidden"`
Recursive *bool `json:"recursive"`
Matches *bool `json:"matches"`
Quiet *bool `json:"quiet"`
Verbose *bool `json:"verbose"`
}

func (cmd *touchCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
Expand All @@ -850,19 +852,29 @@ func (cmd *touchCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
cmd.Matches = fs.Bool(drive.MatchesKey, 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")
cmd.Depth = fs.Int(drive.DepthKey, drive.DefaultMaxTraversalDepth, "max traversal depth")
cmd.Verbose = fs.Bool(drive.CLIOptionVerboseKey, true, drive.DescVerbose)

return fs
}

func (cmd *touchCmd) Run(args []string, definedFlags map[string]*flag.Flag) {
sources, context, path := preprocessArgsByToggle(args, *cmd.Matches || *cmd.ById)

depth := *cmd.Depth
if *cmd.Recursive {
depth = drive.InfiniteDepth
}

opts := drive.Options{
Path: path,
Sources: sources,
Hidden: *cmd.Hidden,
Recursive: *cmd.Recursive,
Depth: depth,
Quiet: *cmd.Quiet,
Match: *cmd.Matches,
Verbose: *cmd.Verbose,
}

if *cmd.Matches {
Expand Down
1 change: 0 additions & 1 deletion src/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,6 @@ func (r *Remote) FindMatches(mq *matchQuery) (chan *File, error) {
parQuery := fmt.Sprintf("(%s in parents)", customQuote(parent.Id))
expr := sepJoinNonEmpty(" and ", parQuery, mq.Stringer())

expr = "(starred=true)"
req.Q(expr)
return reqDoPage(req, true, false), nil
}
Expand Down
17 changes: 11 additions & 6 deletions src/touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (g *Commands) Touch(byId bool) (err error) {
if byId {
fileId = relToRootPath
}
chanMap[i] = g.touch(relToRootPath, fileId)
chanMap[i] = g.touch(relToRootPath, fileId, g.opts.Depth)
<-throttle
}

Expand Down Expand Up @@ -88,7 +88,7 @@ func (g *Commands) TouchByMatch() (err error) {
continue
}

chanMap[i] = g.touch(g.opts.Path+"/"+match.Name, match.Id)
chanMap[i] = g.touch(g.opts.Path+"/"+match.Name, match.Id, g.opts.Depth)
<-throttle
i += 1
}
Expand All @@ -97,7 +97,7 @@ func (g *Commands) TouchByMatch() (err error) {
return
}

func (g *Commands) touch(relToRootPath, fileId string) chan *keyValue {
func (g *Commands) touch(relToRootPath, fileId string, depth int) chan *keyValue {
fileChan := make(chan *keyValue)

go func() {
Expand All @@ -122,11 +122,16 @@ func (g *Commands) touch(relToRootPath, fileId string) chan *keyValue {
return
}

if true { // TODO: Print this out if verbosity is set
if g.opts.Verbose {
g.log.Logf("%s: %v\n", relToRootPath, file.ModTime)
}

if g.opts.Recursive && file.IsDir {
depth = decrementTraversalDepth(depth)
if depth == 0 {
return
}

if file.IsDir {
childResults := make(chan chan *keyValue)
// Arbitrary value for rate limiter
throttle := time.Tick(1e9 * 2)
Expand All @@ -135,7 +140,7 @@ func (g *Commands) touch(relToRootPath, fileId string) chan *keyValue {
go func() {
defer close(childResults)
for child := range childrenChan {
childResults <- g.touch(relToRootPath+"/"+child.Name, child.Id)
childResults <- g.touch(relToRootPath+"/"+child.Name, child.Id, depth)
<-throttle
}
}()
Expand Down