From 54c570413376419f3585c26d0854f724f7ea5444 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Tue, 26 Sep 2017 23:00:08 -0700 Subject: [PATCH] Fixed a bug where it was not possible to flatten the entire collection --- src/index.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/index.rs b/src/index.rs index 1bd70e3..420c3a6 100644 --- a/src/index.rs +++ b/src/index.rs @@ -524,12 +524,18 @@ pub fn flatten(db: &T, virtual_path: &Path) -> Result> use self::songs::dsl::*; let vfs = db.get_vfs()?; let connection = db.get_connection(); - let real_path = vfs.virtual_to_real(virtual_path)?; - let like_path = real_path.as_path().to_string_lossy().into_owned() + "%"; - let real_songs: Vec = songs - .filter(path.like(&like_path)) - .order(path) - .load(connection.deref())?; + + let real_songs: Vec = if virtual_path.parent() != None { + let real_path = vfs.virtual_to_real(virtual_path)?; + let like_path = real_path.as_path().to_string_lossy().into_owned() + "%"; + songs + .filter(path.like(&like_path)) + .order(path) + .load(connection.deref())? + } else { + songs.order(path).load(connection.deref())? + }; + let virtual_songs = real_songs .into_iter() .filter_map(|s| virtualize_song(&vfs, s));