mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	Clean up files if task failed
This commit is contained in:
		| @@ -277,12 +277,12 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void copyFromResource(HashMap<String, ArrayList<File> > map) throws IOException { |     private void copyFromResource(HashMap<String, ArrayList<File> > resToCopy) throws IOException { | ||||||
|         ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(context.getPackageResourcePath()))); |         ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(context.getPackageResourcePath()))); | ||||||
|         ZipEntry ze; |         ZipEntry ze; | ||||||
|         while ((ze = zis.getNextEntry()) != null) { |         while ((ze = zis.getNextEntry()) != null) { | ||||||
|             String fn = ze.getName(); |             String fn = ze.getName(); | ||||||
|             ArrayList<File> targets = map.get(fn); |             ArrayList<File> targets = resToCopy.get(fn); | ||||||
|             if (targets != null) { |             if (targets != null) { | ||||||
|                 File lastTarget = null; |                 File lastTarget = null; | ||||||
|                 for (File target: targets) { |                 for (File target: targets) { | ||||||
| @@ -462,8 +462,9 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected Void doInBackground(DownloadTaskParams... params) { |     protected Void doInBackground(DownloadTaskParams... params) { | ||||||
|  |         int taskType = params[0].type; | ||||||
|         try { |         try { | ||||||
|             switch (params[0].type) { |             switch (taskType) { | ||||||
|                 case DownloadTaskParams.TASK_TYPE_PATCH_FULL: |                 case DownloadTaskParams.TASK_TYPE_PATCH_FULL: | ||||||
|                     doFullPatch(params[0]); |                     doFullPatch(params[0]); | ||||||
|                     break; |                     break; | ||||||
| @@ -489,6 +490,25 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> { | |||||||
|             if (UpdateContext.DEBUG) { |             if (UpdateContext.DEBUG) { | ||||||
|                 e.printStackTrace(); |                 e.printStackTrace(); | ||||||
|             } |             } | ||||||
|  |             File targetToClean = params[0].targetFile; | ||||||
|  |             switch (taskType) { | ||||||
|  |                 case DownloadTaskParams.TASK_TYPE_PATCH_FULL: | ||||||
|  |                 case DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK: | ||||||
|  |                 case DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK: | ||||||
|  |                     try { | ||||||
|  |                         removeDirectory(targetToClean); | ||||||
|  |                     } catch (IOException ioException) { | ||||||
|  |                         ioException.printStackTrace(); | ||||||
|  |                     } | ||||||
|  |                     break; | ||||||
|  |                 case DownloadTaskParams.TASK_TYPE_PLAIN_DOWNLOAD: | ||||||
|  |                     if (targetToClean.exists()) { | ||||||
|  |                         targetToClean.delete(); | ||||||
|  |                     } | ||||||
|  |                     break; | ||||||
|  |                 default: | ||||||
|  |                     break; | ||||||
|  |             } | ||||||
|             Log.e("pushy", "download task failed", e); |             Log.e("pushy", "download task failed", e); | ||||||
|             params[0].listener.onDownloadFailed(e); |             params[0].listener.onDownloadFailed(e); | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm