From 9978bd0caeeb67fb0e7e8e328c4e6944e8bb26ce Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 27 Mar 2019 13:38:58 +0100 Subject: [PATCH] MOBILE-2915 file: Fix delete files with special chars --- src/components/local-file/local-file.ts | 14 +++++++------- src/providers/file.ts | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/local-file/local-file.ts b/src/components/local-file/local-file.ts index f507b2275..b5f3140ec 100644 --- a/src/components/local-file/local-file.ts +++ b/src/components/local-file/local-file.ts @@ -62,13 +62,6 @@ export class CoreLocalFileComponent implements OnInit { ngOnInit(): void { this.manage = this.utils.isTrueOrOne(this.manage); - // Let's calculate the relative path for the file. - this.relativePath = this.fileProvider.removeBasePath(this.file.toURL()); - if (!this.relativePath) { - // Didn't find basePath, use fullPath but if the user tries to manage the file it'll probably fail. - this.relativePath = this.file.fullPath; - } - this.loadFileBasicData(); // Get the size and timemodified. @@ -88,6 +81,13 @@ export class CoreLocalFileComponent implements OnInit { this.fileName = this.file.name; this.fileIcon = this.mimeUtils.getFileIcon(this.file.name); this.fileExtension = this.mimeUtils.getFileExtension(this.file.name); + + // Let's calculate the relative path for the file. + this.relativePath = this.fileProvider.removeBasePath(this.file.toURL()); + if (!this.relativePath) { + // Didn't find basePath, use fullPath but if the user tries to manage the file it'll probably fail. + this.relativePath = this.file.fullPath; + } } /** diff --git a/src/providers/file.ts b/src/providers/file.ts index 579a7745f..a2c53ceb1 100644 --- a/src/providers/file.ts +++ b/src/providers/file.ts @@ -324,7 +324,16 @@ export class CoreFileProvider { path = this.removeStartingSlash(path.replace(this.basePath, '')); this.logger.debug('Remove file: ' + path); - return this.file.removeFile(this.basePath, path); + return this.file.removeFile(this.basePath, path).catch((error) => { + // The delete can fail if the path has encoded characters. Try again if that's the case. + const decodedPath = decodeURI(path); + + if (decodedPath != path) { + return this.file.removeFile(this.basePath, decodedPath); + } else { + return Promise.reject(error); + } + }); }); }