Skip to content

Commit 990b471

Browse files
committed
fixed merge conflicts from master
2 parents 7de9468 + 848497f commit 990b471

File tree

10 files changed

+97
-76
lines changed

10 files changed

+97
-76
lines changed

src/changes.go

+41-8
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ import (
3030
type destination int
3131

3232
const (
33-
SelectSrc = 1 << iota
33+
SelectSrc destination = 1 << iota
3434
SelectDest
3535
)
3636

37+
type Agreement int
38+
39+
const (
40+
NotApplicable Agreement = 1 << iota
41+
Rejected
42+
Accepted
43+
AcceptedImplicitly
44+
)
45+
3746
type dirList struct {
3847
remote *File
3948
local *File
@@ -658,22 +667,46 @@ func previewChanges(clArgs *changeListArg, reduce bool, opMap map[Operation]size
658667
}
659668
}
660669

661-
func printChangeList(clArg *changeListArg) (bool, *map[Operation]sizeCounter) {
670+
func rejected(status Agreement) bool {
671+
return (status & Rejected) != 0
672+
}
673+
674+
func accepted(status Agreement) bool {
675+
return (status&Accepted) != 0 || (status&AcceptedImplicitly) != 0
676+
}
677+
678+
func notApplicable(status Agreement) bool {
679+
return (status & NotApplicable) != 0
680+
}
681+
682+
func (ag *Agreement) Error() error {
683+
switch *ag {
684+
case Rejected:
685+
return ErrRejectedTerms
686+
}
687+
688+
return nil
689+
}
690+
691+
func printChangeList(clArg *changeListArg) (Agreement, *map[Operation]sizeCounter) {
662692
if len(clArg.changes) == 0 {
663693
clArg.logy.Logln("Everything is up-to-date.")
664-
return false, nil
694+
return NotApplicable, nil
665695
}
666696
if !clArg.canPreview {
667-
return true, nil
697+
return AcceptedImplicitly, nil
668698
}
669699

670700
opMap := opChangeCount(clArg.changes)
671701
previewChanges(clArg, true, opMap)
672702

673-
accepted := clArg.noPrompt
674-
if !accepted {
675-
accepted = promptForChanges()
703+
status := Rejected
704+
if clArg.noPrompt {
705+
status = AcceptedImplicitly
706+
}
707+
if !accepted(status) {
708+
status = promptForChanges()
676709
}
677710

678-
return accepted, &opMap
711+
return status, &opMap
679712
}

src/commands.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"github.com/cheggaaa/pb"
2626
"github.com/mattn/go-isatty"
27-
expirable "github.com/odeke-em/cache"
27+
expirableCache "github.com/odeke-em/cache"
2828
"github.com/odeke-em/drive/config"
2929
"github.com/odeke-em/log"
3030
)
@@ -99,7 +99,7 @@ type Commands struct {
9999
log *log.Logger
100100

101101
progress *pb.ProgressBar
102-
mkdirAllCache *expirable.OperationCache
102+
mkdirAllCache *expirableCache.OperationCache
103103
}
104104

105105
func (opts *Options) canPrompt() bool {
@@ -194,7 +194,7 @@ func New(context *config.Context, opts *Options) *Commands {
194194
rem: r,
195195
opts: opts,
196196
log: logger,
197-
mkdirAllCache: expirable.New(),
197+
mkdirAllCache: expirableCache.New(),
198198
}
199199
}
200200

src/edit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func (g *Commands) EditDescription(byId bool) (composedErr error) {
4949

5050
if description == "" && g.opts.canPrompt() {
5151
g.log.Logln("Using an empty description will clear out the previous one")
52-
if !promptForChanges() {
53-
return
52+
if status := promptForChanges(); !accepted(status) {
53+
return status.Error()
5454
}
5555
}
5656

src/fetch.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ func (g *Commands) fetch(fetchOp int) (err error) {
9393
noClobber: g.opts.NoClobber,
9494
}
9595

96-
ok, opMap := printFetchChangeList(&clArg)
97-
if !ok {
98-
return nil
96+
status, opMap := printFetchChangeList(&clArg)
97+
if !accepted(status) {
98+
return status.Error()
9999
}
100100

101101
return g.playFetchChanges(cl, opMap)
@@ -315,13 +315,13 @@ func (g *Commands) createIndex(f *File) (err error) {
315315
return g.context.SerializeIndex(index)
316316
}
317317

318-
func printFetchChangeList(clArg *changeListArg) (bool, *map[Operation]sizeCounter) {
318+
func printFetchChangeList(clArg *changeListArg) (Agreement, *map[Operation]sizeCounter) {
319319
if len(clArg.changes) == 0 {
320320
clArg.logy.Logln("Everything is up-to-date.")
321-
return false, nil
321+
return NotApplicable, nil
322322
}
323323
if clArg.noPrompt {
324-
return true, nil
324+
return AcceptedImplicitly, nil
325325
}
326326

327327
logy := clArg.logy

src/init.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func (g *Commands) DeInit() error {
4444
return true
4545
}
4646

47-
return promptForChanges(args...)
47+
status := promptForChanges(args...)
48+
return accepted(status)
4849
}
4950

5051
return g.context.DeInitialize(prompt, true)

src/misc.go

+15-32
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ import (
3333

3434
"google.golang.org/api/googleapi"
3535

36+
expirableCache "github.com/odeke-em/cache"
3637
spinner "github.com/odeke-em/cli-spinner"
3738
"github.com/odeke-em/drive/config"
3839
)
3940

41+
var (
42+
// ErrRejectedTerms is empty "" because messages might be too
43+
// verbose to affirm a rejection that a user has already seen
44+
ErrRejectedTerms = errors.New("")
45+
)
46+
4047
const (
4148
MimeTypeJoiner = "-"
4249
RemoteDriveRootPath = "My Drive"
@@ -246,7 +253,7 @@ func nextPage() bool {
246253
return true
247254
}
248255

249-
func promptForChanges(args ...interface{}) bool {
256+
func promptForChanges(args ...interface{}) Agreement {
250257
argv := []interface{}{
251258
"Proceed with the changes? [Y/n]:",
252259
}
@@ -260,7 +267,11 @@ func promptForChanges(args ...interface{}) bool {
260267
input = YesShortKey
261268
}
262269

263-
return strings.ToUpper(input) == YesShortKey
270+
if strings.ToUpper(input) == YesShortKey {
271+
return Accepted
272+
}
273+
274+
return Rejected
264275
}
265276

266277
func (f *File) toDesktopEntry(urlMExt *urlMimeTypeExt) *desktopEntry {
@@ -624,36 +635,8 @@ func customQuote(s string) string {
624635
return "\"" + strings.Replace(strings.Replace(s, "\\", "\\\\", -1), "\"", "\\\"", -1) + "\""
625636
}
626637

627-
type expirableCacheValue struct {
628-
value interface{}
629-
entryTime time.Time
630-
}
631-
632-
func (e *expirableCacheValue) Expired(q time.Time) bool {
633-
if e == nil {
634-
return true
635-
}
636-
637-
return e.entryTime.Before(q)
638-
}
639-
640-
func (e *expirableCacheValue) Value() interface{} {
641-
if e == nil {
642-
return nil
643-
}
644-
645-
return e.value
646-
}
647-
648-
func newExpirableCacheValueWithOffset(v interface{}, offset time.Duration) *expirableCacheValue {
649-
return &expirableCacheValue{
650-
value: v,
651-
entryTime: time.Now().Add(offset),
652-
}
653-
}
654-
655-
var newExpirableCacheValue = func(v interface{}) *expirableCacheValue {
656-
return newExpirableCacheValueWithOffset(v, time.Hour)
638+
func newExpirableCacheValue(v interface{}) *expirableCache.ExpirableValue {
639+
return expirableCache.NewExpirableValueWithOffset(v, uint64(time.Hour))
657640
}
658641

659642
func reComposeError(prevErr error, messages ...string) error {

src/pull.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ func pull(g *Commands, pt pullType) error {
119119
canPreview: g.opts.canPreview(),
120120
}
121121

122-
ok, opMap := printChangeList(&clArg)
123-
if !ok {
124-
return nil
122+
status, opMap := printChangeList(&clArg)
123+
if !accepted(status) {
124+
return status.Error()
125125
}
126126

127127
return g.playPullChanges(nonConflicts, g.opts.Exports, opMap)
@@ -173,7 +173,8 @@ func autoRenameClashes(g *Commands, clashes []*Change) error {
173173
for _, r := range renames {
174174
g.log.Logf("%v %v -> %v\n", r.originalPath, r.change.Src.Id, r.newName)
175175
}
176-
if !promptForChanges("Proceed with the changes [Y/N] ? ") {
176+
status := promptForChanges("Proceed with the changes [Y/N] ? ")
177+
if !accepted(status) {
177178
return ErrClashesDetected
178179
}
179180
}

src/push.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ func (g *Commands) Push() (err error) {
134134
}
135135

136136
g.log.LogErrf(" %s", unSafeQuotaMsg)
137-
if !promptForChanges() {
138-
return
137+
if status := promptForChanges(); !accepted(status) {
138+
return status.Error()
139139
}
140140
}
141141

@@ -147,9 +147,9 @@ func (g *Commands) Push() (err error) {
147147
canPreview: g.opts.canPreview(),
148148
}
149149

150-
ok, opMap := printChangeList(&clArg)
151-
if !ok {
152-
return
150+
status, opMap := printChangeList(&clArg)
151+
if !accepted(status) {
152+
return status.Error()
153153
}
154154

155155
return g.playPushChanges(nonConflicts, opMap)

src/share.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ func (c *Commands) Share(byId bool) (err error) {
175175
return c.share(false, byId)
176176
}
177177

178-
func showPromptShareChanges(logy *log.Logger, change *shareChange) bool {
178+
func showPromptShareChanges(logy *log.Logger, change *shareChange) Agreement {
179179
if len(change.files) < 1 {
180-
return false
180+
return NotApplicable
181181
}
182182
if change.revoke {
183183
logy.Logf("Revoke access for accountType: \033[92m%s\033[00m for file(s):\n",
@@ -190,7 +190,7 @@ func showPromptShareChanges(logy *log.Logger, change *shareChange) bool {
190190
}
191191

192192
if len(change.emails) < 1 {
193-
return false
193+
return NotApplicable
194194
}
195195

196196
if change.notify {
@@ -213,8 +213,10 @@ func showPromptShareChanges(logy *log.Logger, change *shareChange) bool {
213213
}
214214

215215
func (c *Commands) playShareChanges(change *shareChange) error {
216-
if c.opts.canPrompt() && !showPromptShareChanges(c.log, change) {
217-
return nil
216+
if c.opts.canPrompt() {
217+
if status := showPromptShareChanges(c.log, change); !accepted(status) {
218+
return status.Error()
219+
}
218220
}
219221

220222
for _, file := range change.files {

src/trash.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func (g *Commands) EmptyTrash() error {
7878

7979
g.log.Logln("This operation is irreversible. Empty trash! ")
8080

81-
if !promptForChanges() {
81+
if status := promptForChanges(); !accepted(status) {
8282
g.log.Logln("Aborted emptying trash")
83-
return nil
83+
return status.Error()
8484
}
8585
}
8686

@@ -168,9 +168,9 @@ func (g *Commands) trashByMatch(inTrash, permanent bool) error {
168168
noClobber: false,
169169
}
170170

171-
ok, _ := printChangeList(&clArg)
172-
if !ok {
173-
return nil
171+
status, _ := printChangeList(&clArg)
172+
if !accepted(status) {
173+
return status.Error()
174174
}
175175

176176
toTrash := !inTrash
@@ -212,14 +212,15 @@ func (g *Commands) reduceForTrash(args []string, opt *trashOpt) error {
212212
noClobber: false,
213213
}
214214

215-
ok, _ := printChangeList(&clArg)
216-
if !ok {
217-
return nil
215+
status, _ := printChangeList(&clArg)
216+
if !accepted(status) {
217+
return status.Error()
218218
}
219219

220220
if opt.permanent && g.opts.canPrompt() {
221-
if !promptForChanges("This operation is irreversible. Continue [Y/N] ") {
222-
return nil
221+
status := promptForChanges("This operation is irreversible. Continue [Y/N] ")
222+
if !accepted(status) {
223+
return status.Error()
223224
}
224225
}
225226
return g.playTrashChangeList(cl, opt)

0 commit comments

Comments
 (0)