Skip to content

Commit 5aadbd1

Browse files
committed
MOBILE-1408 filepool: Fix download errors in iOS because of some chars
1 parent f3da60a commit 5aadbd1

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

www/core/lib/emulator.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ angular.module('mm.core')
6565
errorCallback();
6666
} else {
6767
filePath = filePath.replace(basePath, ''); // Remove basePath from the filePath.
68+
filePath = filePath.replace(/%20/g, ' '); // Replace all %20 with spaces.
6869
$mmFS.writeFile(filePath, data.data).then(function(e) {
6970
successCallback(e);
7071
}).catch(function(error) {
@@ -81,7 +82,9 @@ angular.module('mm.core')
8182
unzip: function(source, destination, callback, progressCallback) {
8283
// Remove basePath from the source and destination.
8384
source = source.replace(basePath, '');
85+
source = source.replace(/%20/g, ' '); // Replace all %20 with spaces.
8486
destination = destination.replace(basePath, '');
87+
destination = destination.replace(/%20/g, ' '); // Replace all %20 with spaces.
8588

8689
$mmFS.readFile(source, $mmFS.FORMATARRAYBUFFER).then(function(data) {
8790
var zip = new JSZip(data),

www/core/lib/fs.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -914,11 +914,12 @@ angular.module('mm.core')
914914
* @return {Promise} Promise resolved when the file is unzipped.
915915
*/
916916
self.unzipFile = function(path, destFolder) {
917-
// We need to use ansolute paths (including basePath).
918-
path = self.addBasePathIfNeeded(path);
919-
// If destFolder is not set, use same location as ZIP file.
920-
destFolder = self.addBasePathIfNeeded(destFolder || self.removeExtension(path));
921-
return $cordovaZip.unzip(path, destFolder);
917+
// Get the source file.
918+
return self.getFile(path).then(function(fileEntry) {
919+
// If destFolder is not set, use same location as ZIP file. We need to use ansolute paths (including basePath).
920+
destFolder = self.addBasePathIfNeeded(destFolder || self.removeExtension(path));
921+
return $cordovaZip.unzip(fileEntry.toURL(), destFolder);
922+
});
922923
};
923924

924925
return self;

www/core/lib/ws.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)