From e0d0936001bec0bdd6af4fe3684ff0e9af4ca00d Mon Sep 17 00:00:00 2001 From: Petko Ditchev Date: Thu, 28 Feb 2019 20:03:42 +0200 Subject: [PATCH] Fix relative path resolution (#928) When you have a music folder /music and a playlists folder /music/playlists , then reading a playlist with a song ../a.mp3 inside resolved to "/music/playlists/../a.mp3" , which broke the import operation. Using getCanonicalPath instead of getAbsolutePath fixes the issue, since the former resolves the URI to /music/a.mp3 --- .../java/ch/blinkenlights/android/vanilla/FileUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/FileUtils.java b/app/src/main/java/ch/blinkenlights/android/vanilla/FileUtils.java index 3405f92e..4c942b60 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/FileUtils.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/FileUtils.java @@ -20,6 +20,7 @@ package ch.blinkenlights.android.vanilla; import ch.blinkenlights.android.medialibrary.MediaLibrary; import java.io.File; +import java.io.IOException; import java.net.URI; import java.net.URLConnection; import java.net.URISyntaxException; @@ -142,10 +143,12 @@ public class FileUtils { try { if (!destination.isAbsolute()) { - path = new File(base, path).getAbsolutePath(); + path = new File(base, path).getCanonicalPath(); } } catch (SecurityException ex) { // Ignore. + }catch (IOException ex){ + // Ignore } return path; }