Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6916b03e authored by Vasu Nori's avatar Vasu Nori
Browse files

if a download dir doesn't exist, create it or fail fast

in HC, using DownloadManager public API, download directories
named by the constants Environment.DOWNLOAD_*
may ot exist. theyneed to be created or
the download request should fail ASAP.
bug:3297328

Change-Id: Ic87023d8fe98bd240744f66607a5400b7825e17e
parent 4c7cc341
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -453,7 +453,19 @@ public class DownloadManager {
         * @return this object
         */
        public Request setDestinationInExternalPublicDir(String dirType, String subPath) {
            setDestinationFromBase(Environment.getExternalStoragePublicDirectory(dirType), subPath);
            File file = Environment.getExternalStoragePublicDirectory(dirType);
            if (file.exists()) {
                if (!file.isDirectory()) {
                    throw new IllegalStateException(file.getAbsolutePath() +
                            " already exists and is not a directory");
                }
            } else {
                if (!file.mkdir()) {
                    throw new IllegalStateException("Unable to create directory: "+
                            file.getAbsolutePath());
                }
            }
            setDestinationFromBase(file, subPath);
            return this;
        }