/*
	Actually get a list of directories or files from the dropbox connection
*/
func get(cache *cache.Cache, db *dropbox.Dropbox, path string, directories bool) []dropbox.Entry {
	// Use caching to reduce calls to the Dropbox API
	var cache_descriptor string
	if directories {
		cache_descriptor = "dirs:"
	} else {
		cache_descriptor = "files:"
	}
	s := []string{}
	s = append(s, cache_descriptor)
	s = append(s, path)
	cache_path := strings.Join(s, "")

	data, found := cache.Get(cache_path)
	if found {
		if cached_paths, ok := data.([]dropbox.Entry); ok {
			return (cached_paths)
		} else {
			log.Println("Error: Unable to retrieve from cache")
		}
	}

	entry, err := db.Metadata(path, true, false, "", "", 500)
	if err != nil {
		log.Println(err)
		return []dropbox.Entry{}
	}
	paths := make([]dropbox.Entry, 0)
	for i := 0; i < len(entry.Contents); i++ {
		entry := entry.Contents[i]
		if directories {
			if entry.IsDir {
				paths = append(paths, entry)
			}
		} else {
			if !entry.IsDir {
				include := true
				for _, lookup := range do_not_include {
					if strings.Contains(entry.Path, lookup) {
						include = false
					}
				}
				if include {
					paths = append(paths, entry)
				}
			}
		}
	}
	cache.Set(cache_path, paths, 0)
	return paths
}