Skip to content

Commit

Permalink
fix(android): java deployFromZip() and deployFromAssets()
Browse files Browse the repository at this point in the history
- Regression caused by TIMOB-28246 change.
- Nobody uses these methods.
  • Loading branch information
jquick-axway committed Nov 20, 2020
1 parent 6ff7bb4 commit 09db253
Showing 1 changed file with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ public void deployFromAssets(File dest) throws IOException
AssetManager am = ctx.getAssets();
walkAssets(am, "", paths);

// TODO clean old dir
deleteTree(dest);
// Delete all files and subdirectories under given directory.
emptyDirectory(dest);

// copy from assets to dest dir
BufferedInputStream bis = null;
Expand Down Expand Up @@ -462,7 +462,7 @@ public void deployFromAssets(File dest) throws IOException

public void deployFromZip(File fname, File dest) throws IOException
{
deleteTree(dest);
emptyDirectory(dest);

ZipInputStream zis = null;
ZipEntry ze = null;
Expand Down Expand Up @@ -573,6 +573,40 @@ public boolean deleteTree(File file) throws SecurityException
return (wasDeleted && file.delete());
}

/**
* Deletes all files and subdirectories under the given directory while leaving the given directory intact.
* If given directory does not exist, then it is created.
* @param directory The directory to be emptied. Can be null.
* @return
* Returns true if successfully deleted all files and folders under given directory.
* Returns false if at least 1 deletion failed or if given a null argument.
* @exception SecurityException Thrown if don't have permission to delete at least 1 file in the tree.
*/
public boolean emptyDirectory(File directory) throws SecurityException
{
// Validate argument.
if (directory == null) {
return false;
}

// If directory does not exist, then create it and stop here.
if (!directory.exists()) {
return directory.mkdirs();
}

// Do not continue if referencing a file instead of a directory.
if (!directory.isDirectory()) {
return false;
}

// Delete all file and subdirectories under given directory.
boolean wasSuccessful = true;
for (File nextFile : directory.listFiles()) {
wasSuccessful = deleteTree(nextFile) && wasSuccessful;
}
return wasSuccessful;
}

public File getTempFile(String suffix, boolean destroyOnExit) throws IOException
{
TiApplication tiApp = TiApplication.getInstance();
Expand Down

0 comments on commit 09db253

Please sign in to comment.