fix the mystery crash. fuck im retarded

This commit is contained in:
Cyberes 2024-03-15 19:10:24 -06:00
parent c73d17a2ec
commit 115bd60ec5
1 changed files with 30 additions and 25 deletions

View File

@ -8,7 +8,6 @@ import (
"crazyfs/logging"
"github.com/sirupsen/logrus"
"path/filepath"
"runtime/debug"
)
var log *logrus.Logger
@ -33,27 +32,29 @@ type ResponseItem struct {
}
func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem {
defer func() {
if r := recover(); r != nil {
copiedItem := &CacheItem.Item{
Path: cacheItem.Path,
Name: cacheItem.Name,
Size: cacheItem.Size,
Extension: cacheItem.Extension,
Modified: cacheItem.Modified,
Mode: cacheItem.Mode,
IsDir: cacheItem.IsDir,
IsSymlink: cacheItem.IsSymlink,
Cached: cacheItem.Cached,
Children: nil,
MimeType: cacheItem.MimeType,
}
// TODO: this should never happen and can probably be removed.
// Problem was linked to the scenario where an item was not found in the cache
// so a new crawl was triggered but the `childItem` var was never updated.
//defer func() {
// if r := recover(); r != nil {
// copiedItem := &CacheItem.Item{
// Path: cacheItem.Path,
// Name: cacheItem.Name,
// Size: cacheItem.Size,
// Extension: cacheItem.Extension,
// Modified: cacheItem.Modified,
// Mode: cacheItem.Mode,
// IsDir: cacheItem.IsDir,
// IsSymlink: cacheItem.IsSymlink,
// Cached: cacheItem.Cached,
// Children: nil,
// MimeType: cacheItem.MimeType,
// }
// log.Fatalf("Recovered from panic: %s - %+v - %s", r, copiedItem, debug.Stack())
// }
//}()
log.Fatalf("Recovered from panic: %s - %+v - %s", r, copiedItem, debug.Stack())
}
}()
item := &ResponseItem{
newResponseItem := &ResponseItem{
Path: cacheItem.Path,
Name: cacheItem.Name,
Size: cacheItem.Size,
@ -67,7 +68,7 @@ func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem {
Type: cacheItem.MimeType,
}
// Grab the children from the cache and add them to this new item
// Grab the children from the cache and add them to this new newResponseItem
if len(cacheItem.Children) > 0 { // avoid a null entry for the children key in the JSON
var children []*CacheItem.Item
for _, child := range cacheItem.Children {
@ -89,6 +90,8 @@ func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem {
log.Debugf("NewResponseItem - CrawlNoRecursion - not found %s - likely broken symlink", child)
continue
}
// Update the `childItem` var with the newly cached item.
childItem = item
}
if childItem != nil {
@ -107,11 +110,13 @@ func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem {
}
children = append(children, copiedChildItem)
} else {
log.Errorf(`NewResponseItem - copiedChildItem for "%s" was null! - %+v`, child, cacheItem)
// This should never happen but we've had issues in the past so it's a safety check.
log.Errorf(`NewResponseItem - copiedChildItem for "%s" was null!`, child)
continue
}
}
item.Children = children
newResponseItem.Children = children
}
return item
return newResponseItem
}