@@ -148,20 +148,22 @@ angular.module('mm.core')
148148 self . downloadFile = function ( url , path , background ) {
149149 $log . debug ( 'Downloading file ' + url ) ;
150150
151- return $mmFS . getBasePathToDownload ( ) . then ( function ( basePath ) {
152- // Use a tmp path to download the file and then move it to final location. This is because if the download fails,
153- // the local file is deleted.
154- var tmpPath = basePath + path + '.tmp' ;
155- return $cordovaFileTransfer . download ( url , tmpPath , { encodeURI : false } , true ) . then ( function ( ) {
156- return $mmFS . moveFile ( path + '.tmp' , path ) . then ( function ( movedEntry ) {
151+ // Use a tmp path to download the file and then move it to final location.This is because if the download fails,
152+ // the local file is deleted.
153+ var tmpPath = path + '.tmp' ;
154+
155+ // Create the tmp file as an empty file.
156+ return $mmFS . createFile ( tmpPath ) . then ( function ( fileEntry ) {
157+ return $cordovaFileTransfer . download ( url , fileEntry . toURL ( ) , { encodeURI : false } , true ) . then ( function ( ) {
158+ return $mmFS . moveFile ( tmpPath , path ) . then ( function ( movedEntry ) {
157159 $log . debug ( 'Success downloading file ' + url + ' to ' + path ) ;
158160 return movedEntry ;
159161 } ) ;
160- } , function ( err ) {
161- $log . error ( 'Error downloading ' + url + ' to ' + path ) ;
162- $log . error ( JSON . stringify ( err ) ) ;
163- return $q . reject ( err ) ;
164162 } ) ;
163+ } ) . catch ( function ( err ) {
164+ $log . error ( 'Error downloading ' + url + ' to ' + path ) ;
165+ $log . error ( JSON . stringify ( err ) ) ;
166+ return $q . reject ( err ) ;
165167 } ) ;
166168 } ;
167169
0 commit comments