Skip to content

Commit

Permalink
Merge branch 'v0.3.1-beta' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
WizardOfCodez committed Jan 9, 2021
2 parents 90c3b50 + 60cd010 commit 7f6f538
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
34 changes: 22 additions & 12 deletions surge/FileListSorting.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package surge

import "strings"

/*type Interface interface {
// Len is the number of elements in the collection.
Len() int
Expand All @@ -24,15 +26,19 @@ func (a sortBySeederCountDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

type sortByFileNameAsc []FileListing

func (a sortByFileNameAsc) Len() int { return len(a) }
func (a sortByFileNameAsc) Less(i, j int) bool { return a[i].FileName < a[j].FileName }
func (a sortByFileNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a sortByFileNameAsc) Len() int { return len(a) }
func (a sortByFileNameAsc) Less(i, j int) bool {
return strings.ToLower(a[i].FileName) < strings.ToLower(a[j].FileName)
}
func (a sortByFileNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

type sortByFileNameDesc []FileListing

func (a sortByFileNameDesc) Len() int { return len(a) }
func (a sortByFileNameDesc) Less(i, j int) bool { return a[i].FileName > a[j].FileName }
func (a sortByFileNameDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a sortByFileNameDesc) Len() int { return len(a) }
func (a sortByFileNameDesc) Less(i, j int) bool {
return strings.ToLower(a[i].FileName) > strings.ToLower(a[j].FileName)
}
func (a sortByFileNameDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

type sortByFileSizeAsc []FileListing

Expand All @@ -48,12 +54,16 @@ func (a sortByFileSizeDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

type sortLocalByFileNameAsc []File

func (a sortLocalByFileNameAsc) Len() int { return len(a) }
func (a sortLocalByFileNameAsc) Less(i, j int) bool { return a[i].FileName < a[j].FileName }
func (a sortLocalByFileNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a sortLocalByFileNameAsc) Len() int { return len(a) }
func (a sortLocalByFileNameAsc) Less(i, j int) bool {
return strings.ToLower(a[i].FileName) < strings.ToLower(a[j].FileName)
}
func (a sortLocalByFileNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

type sortLocalByFileNameDesc []File

func (a sortLocalByFileNameDesc) Len() int { return len(a) }
func (a sortLocalByFileNameDesc) Less(i, j int) bool { return a[i].FileName > a[j].FileName }
func (a sortLocalByFileNameDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a sortLocalByFileNameDesc) Len() int { return len(a) }
func (a sortLocalByFileNameDesc) Less(i, j int) bool {
return strings.ToLower(a[i].FileName) > strings.ToLower(a[j].FileName)
}
func (a sortLocalByFileNameDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
2 changes: 0 additions & 2 deletions surge/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func downloadChunks(file *File, randomChunks []int) {
//Check if file is still tracked in surge
if err != nil {
log.Println("Download Job Terminated", "File no longer in DB")
pushError("Download Job Terminated", "File no longer in DB")
return
}

Expand All @@ -151,7 +150,6 @@ func downloadChunks(file *File, randomChunks []int) {
dbFile, err = dbGetFile(file.FileHash)
if err != nil {
log.Println("Download Job Terminated", "File no longer in DB")
pushError("Download Job Terminated", "File no longer in DB")
return
}

Expand Down
4 changes: 0 additions & 4 deletions surge/sessionmanager/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ func closeSession(address string) {
sessionLockMapLock.Lock()
defer sessionLockMapLock.Unlock()

sessionLockMapLock.Lock()
session, exists := sessionMap[address]
sessionLockMapLock.Unlock()

//Close nkn session, nill out the pointers
if exists {
Expand All @@ -249,9 +247,7 @@ func closeSession(address string) {
session = nil

//Delete from the map
sessionLockMapLock.Lock()
delete(sessionMap, address)
sessionLockMapLock.Unlock()

log.Println("Download Session closed for: ", address)
fmt.Println(string("\033[31m"), "Download Session closed for: ", address, string("\033[0m"))
Expand Down

0 comments on commit 7f6f538

Please sign in to comment.