Skip to content

Commit

Permalink
Add handling for file count limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Tihomirov committed Jan 7, 2017
1 parent be32bc6 commit aa8e6b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/gowo/cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ package cmd

import (
"log"
"sync"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"sync"

"github.com/fsnotify/fsnotify"
"github.com/whats-this/owo.go"
)

var queue = make(map[string]struct{})
Expand Down Expand Up @@ -67,6 +67,9 @@ var watchCmd = &cobra.Command{
var names []string
queueLock.Lock()
for name := range queue {
if len(names) == owo.FileCountLimit {
break
}
names = append(names, name)
delete(queue, name)
}
Expand Down
13 changes: 13 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

// FilesToNamedReaders Converts a list of file names to named readers.
func FilesToNamedReaders(names []string) (files []NamedReader, err error) {
if len(names) > FileCountLimit {
err = ErrTooManyFiles{len(names)}
return
}
files = make([]NamedReader, len(names))
var file *os.File
var stat os.FileInfo
Expand Down Expand Up @@ -73,3 +77,12 @@ func humanateBytes(s uint64, base float64, sizes []string) string {

return fmt.Sprintf(f, val, suffix)
}

// ErrTooManyFiles thrown when file count in upload exceeds filecount limit
type ErrTooManyFiles struct {
Count int
}

func (e ErrTooManyFiles) Error() string {
return fmt.Sprintf("[pre-flight] Too many files (%d > %d)", e.Count, FileCountLimit)
}

0 comments on commit aa8e6b7

Please sign in to comment.