Skip to content

Commit

Permalink
quota limit handled
Browse files Browse the repository at this point in the history
This fixes issue rakyll#31.
  • Loading branch information
Emmanuel Odeke committed Jan 6, 2015
1 parent bf337b0 commit b436f5a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
28 changes: 24 additions & 4 deletions changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ func merge(remotes, locals []*File) (merged []*dirList) {
return
}

func reduceToSize(changes []*Change, isPush bool) (totalSize int64) {
totalSize = 0
for _, c := range changes {
if isPush {
if c.Src != nil {
totalSize += c.Src.Size
}
} else {
if c.Dest != nil {
totalSize += c.Dest.Size
}
}
}
return totalSize
}

func summarizeChanges(changes []*Change, reduce bool) {
for _, c := range changes {
if c.Op() != OpNone {
Expand Down Expand Up @@ -242,6 +258,13 @@ func summarizeChanges(changes []*Change, reduce bool) {
}
}

func promptForChanges() bool {
input := "Y"
fmt.Print("Proceed with the changes? [Y/n]: ")
fmt.Scanln(&input)
return strings.ToUpper(input) == "Y"
}

func printChangeList(changes []*Change, noPrompt bool, noClobber bool) bool {
if len(changes) == 0 {
fmt.Println("Everything is up-to-date.")
Expand All @@ -254,8 +277,5 @@ func printChangeList(changes []*Change, noPrompt bool, noClobber bool) bool {
return true
}

input := "Y"
fmt.Print("Proceed with the changes? [Y/n]: ")
fmt.Scanln(&input)
return strings.ToUpper(input) == "Y"
return promptForChanges()
}
21 changes: 20 additions & 1 deletion push.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,28 @@ func (g *Commands) Push() (err error) {

ok := printChangeList(cl, g.opts.NoPrompt, g.opts.NoClobber)
if ok {
pushSize := reduceToSize(cl, true)

quotaStatus, qErr := g.QuotaStatus(pushSize)
if qErr != nil {
return qErr
}
unSafe := false
switch quotaStatus {
case AlmostExceeded:
fmt.Println("\033[92mAlmost exceeding your drive quota\033[00m")
case Exceeded:
fmt.Println("\033[91mThis change will exceed your drive quota\033[00m")
unSafe = true
}
if unSafe {
fmt.Printf(" projected size: %d (%d)\n", pushSize, prettyBytes(pushSize))
if !promptForChanges() {
return
}
}
return g.playPushChangeList(cl)
}

return
}

Expand Down
16 changes: 9 additions & 7 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,24 @@ func (f *File) MatchDirness(g *File) bool {
}

// if it's a regular file, see it it's modified.
// If the first test passes, then do an Md5 checksum comparison
// The bare minimum case comparison
func isSameFile(src, dest *File) bool {
if src.Size != dest.Size || !src.ModTime.Equal(dest.ModTime) {
return false
}
if src.IsDir != dest.IsDir {
return false
}
return true
}

ssum := md5Checksum(src)
dsum := md5Checksum(dest)

if dsum != ssum {
// If the preliminary isSameFile test passes,
// then perform an Md5 checksum comparison
func isSameFileTillChecksum(src, dest *File) bool {
if !isSameFile(src, dest) {
return false
}
return true
return md5Checksum(src) == md5Checksum(dest)
}

// Will turn any other op but an Addition into a noop
Expand Down Expand Up @@ -209,7 +211,7 @@ func (c *Change) Op() int {
return OpMod
}

if !c.Src.IsDir && !isSameFile(c.Src, c.Dest) {
if !c.Src.IsDir && !isSameFileTillChecksum(c.Src, c.Dest) {
return OpMod
}
return OpNone
Expand Down

0 comments on commit b436f5a

Please sign in to comment.