Skip to content

Commit

Permalink
fix: if empty folder
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Feb 15, 2022
1 parent a41e0d6 commit d7bf6d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,25 @@ private Boolean unzip(String source, String dest) {
return true;
}
}
private void flattenAssets(String source, String dest) {
private Boolean flattenAssets(String source, String dest) {
File current = new File(this.context.getFilesDir() + "/" + source);
if (!current.exists()) {
return false;
}
File fDest = new File(this.context.getFilesDir() + "/" + dest);
fDest.getParentFile().mkdirs();
String[] pathsName = current.list();
if (pathsName == null || pathsName.length == 0) {
return false;
}
if (pathsName.length == 1 && !pathsName[0].equals("index.html")) {
File newFlat = new File(current.getPath() + "/" + pathsName[0]);
newFlat.renameTo(fDest);
} else {
current.renameTo(fDest);
}
current.delete();
return true;
}

private Boolean downloadFile(String url, String dest) throws JSONException {
Expand Down Expand Up @@ -168,7 +175,8 @@ public String download(String url) {
Boolean unzipped = this.unzip(folderNameZip, folderNameUnZip);
if(!unzipped) return null;
fileZip.delete();
this.flattenAssets(folderNameUnZip, folderName);
Boolean flatt = this.flattenAssets(folderNameUnZip, folderName);
if(!flatt) return null;
return version;
} catch (Exception e) {
Log.e(TAG, "updateApp error", e);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-updater",
"version": "1.3.4",
"version": "1.3.5",
"license": "AGPL-3.0-only",
"description": "Download app update from url",
"main": "dist/plugin.cjs.js",
Expand Down

0 comments on commit d7bf6d0

Please sign in to comment.