MOBILE-2915 file: Fix delete files with special chars

main
Dani Palou 2019-03-27 13:38:58 +01:00
parent ba27f75324
commit 9978bd0cae
2 changed files with 17 additions and 8 deletions

View File

@ -62,13 +62,6 @@ export class CoreLocalFileComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.manage = this.utils.isTrueOrOne(this.manage); 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(); this.loadFileBasicData();
// Get the size and timemodified. // Get the size and timemodified.
@ -88,6 +81,13 @@ export class CoreLocalFileComponent implements OnInit {
this.fileName = this.file.name; this.fileName = this.file.name;
this.fileIcon = this.mimeUtils.getFileIcon(this.file.name); this.fileIcon = this.mimeUtils.getFileIcon(this.file.name);
this.fileExtension = this.mimeUtils.getFileExtension(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;
}
} }
/** /**

View File

@ -324,7 +324,16 @@ export class CoreFileProvider {
path = this.removeStartingSlash(path.replace(this.basePath, '')); path = this.removeStartingSlash(path.replace(this.basePath, ''));
this.logger.debug('Remove file: ' + path); 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);
}
});
}); });
} }