func handleFolderForFolder(fullPath string, stat os.FileInfo) { // update folder table for browsing by folder modTime := stat.ModTime() var folder db.Folder err := tx.Where("path = ?", fullPath).First(&folder).Error if !gorm.IsRecordNotFoundError(err) && modTime.Before(folder.UpdatedAt) { // we found the record but it hasn't changed currentDirStack.Push(&folder) return } _, folderName := path.Split(fullPath) folder.Path = fullPath folder.ParentID = currentDirStack.PeekID() folder.Name = folderName tx.Save(&folder) currentDirStack.Push(&folder) } func handleFolderForAlbum(fullPath string, stat os.FileInfo) { // update album table (the currentAlbum record will be updated when // we exit this folder) err := tx.Where("path = ?", fullPath).First(¤tAlbum).Error if !gorm.IsRecordNotFoundError(err) { // we found the record // TODO: think about mod time here return } currentAlbum = db.Album{Path: fullPath} fmt.Println("SAVING", fullPath, err) tx.Save(¤tAlbum) } func handleFolder(fullPath string, stat os.FileInfo) error { handleFolderForAlbum(fullPath, stat) handleFolderForFolder(fullPath, stat) return nil }