diff --git a/surge/FileListSorting.go b/surge/FileListSorting.go index ff40db5..ae2031f 100644 --- a/surge/FileListSorting.go +++ b/surge/FileListSorting.go @@ -1,5 +1,7 @@ package surge +import "strings" + /*type Interface interface { // Len is the number of elements in the collection. Len() int @@ -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 @@ -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] } diff --git a/surge/download.go b/surge/download.go index a5c52ff..ed1773a 100644 --- a/surge/download.go +++ b/surge/download.go @@ -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 } @@ -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 } diff --git a/surge/sessionmanager/session.go b/surge/sessionmanager/session.go index b40731c..9857bb2 100644 --- a/surge/sessionmanager/session.go +++ b/surge/sessionmanager/session.go @@ -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 { @@ -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"))