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
This commit is contained in:
Petko Ditchev 2019-02-28 20:03:42 +02:00 committed by Adrian Ulrich
parent 199cbcfee1
commit e0d0936001

View File

@ -20,6 +20,7 @@ package ch.blinkenlights.android.vanilla;
import ch.blinkenlights.android.medialibrary.MediaLibrary; import ch.blinkenlights.android.medialibrary.MediaLibrary;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -142,10 +143,12 @@ public class FileUtils {
try { try {
if (!destination.isAbsolute()) { if (!destination.isAbsolute()) {
path = new File(base, path).getAbsolutePath(); path = new File(base, path).getCanonicalPath();
} }
} catch (SecurityException ex) { } catch (SecurityException ex) {
// Ignore. // Ignore.
}catch (IOException ex){
// Ignore
} }
return path; return path;
} }