 Issue 29347192:
  Issue 4181 - Fix FilterEngineTest tests  (Closed)
    
  
    Issue 29347192:
  Issue 4181 - Fix FilterEngineTest tests  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 1 /* | 1 /* | 
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH | 
| 4 * | 4 * | 
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as | 
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. | 
| 8 * | 8 * | 
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, | 
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. | 
| 13 * | 13 * | 
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License | 
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| 16 */ | 16 */ | 
| 17 | 17 | 
| 18 package org.adblockplus.libadblockplus; | 18 package org.adblockplus.libadblockplus; | 
| 19 | 19 | 
| 20 import org.adblockplus.android.Utils; | |
| 21 | |
| 20 import android.util.Log; | 22 import android.util.Log; | 
| 21 | 23 | 
| 22 import java.io.File; | 24 import java.io.File; | 
| 23 import java.util.UUID; | 25 import java.util.UUID; | 
| 24 | 26 | 
| 25 public class FileSystemUtils | 27 public class FileSystemUtils | 
| 
anton
2016/08/08 07:52:51
also renamed FileSystemHelper to FileSystemUtils t
 | |
| 26 { | 28 { | 
| 27 private static final String TAG = FileSystemUtils.class.getSimpleName(); | 29 private static final String TAG = Utils.getTag(FileSystemUtils.class); | 
| 
diegocarloslima
2016/09/09 01:34:14
You might want to use Utils.getTag() to be consist
 
anton
2016/09/09 06:50:53
Acknowledged.
 | |
| 28 | 30 | 
| 29 // File.createTempFile() creates a file instead of just generating unique file name | 31 // File.createTempFile() creates a file instead of just generating unique file name | 
| 30 | 32 | 
| 31 public String generateUniqueFileName(String prefix, String suffix) | 33 public static String generateUniqueFileName(String prefix, String suffix) | 
| 32 { | 34 { | 
| 33 StringBuilder sb = new StringBuilder(); | 35 StringBuilder sb = new StringBuilder(); | 
| 34 if (prefix != null) | 36 if (prefix != null) | 
| 35 { | 37 { | 
| 36 sb.append(prefix); | 38 sb.append(prefix); | 
| 37 } | 39 } | 
| 38 sb.append(UUID.randomUUID()); | 40 sb.append(UUID.randomUUID()); | 
| 39 if (suffix != null) | 41 if (suffix != null) | 
| 40 { | 42 { | 
| 41 sb.append(suffix); | 43 sb.append(suffix); | 
| 42 } | 44 } | 
| 43 return sb.toString(); | 45 return sb.toString(); | 
| 44 } | 46 } | 
| 45 | 47 | 
| 46 public File generateUniqueFileName(String prefix, String suffix, File parent) | 48 public static File generateUniqueFile(String prefix, String suffix, File paren t) | 
| 47 { | 49 { | 
| 48 return new File(parent, generateUniqueFileName(prefix, suffix)); | 50 return new File(parent, generateUniqueFileName(prefix, suffix)); | 
| 49 } | 51 } | 
| 
diegocarloslima
2016/09/09 01:34:14
I think that it would be more consistent if both o
 
anton
2016/09/09 06:50:53
Acknowledged.
 | |
| 50 | 52 | 
| 51 public void delete(String filePath, boolean deleteSelf) | 53 public static void delete(String filePath, boolean deleteSelf) | 
| 
Felix Dahlke
2017/05/09 08:06:45
I may have missed something, but it appears `delet
 
anton
2017/05/10 11:00:14
Done.
 | |
| 52 { | 54 { | 
| 53 delete(new File(filePath), deleteSelf); | 55 delete(new File(filePath), deleteSelf); | 
| 54 } | 56 } | 
| 55 | 57 | 
| 56 public void delete(File file, boolean deleteSelf) | 58 public static void delete(File file, boolean deleteSelf) | 
| 57 { | 59 { | 
| 58 if (file.isDirectory()) | 60 if (file.isDirectory()) | 
| 59 { | 61 { | 
| 60 deleteDirectory(file, deleteSelf); | 62 deleteDirectory(file, deleteSelf); | 
| 61 } | 63 } | 
| 62 else | 64 else | 
| 63 { | 65 { | 
| 64 deleteFile(file); | 66 deleteFile(file); | 
| 65 } | 67 } | 
| 66 } | 68 } | 
| 67 | 69 | 
| 68 public void deleteDirectory(File directory, boolean deleteSelf) | 70 public static void deleteDirectory(File directory, boolean deleteSelf) | 
| 69 { | 71 { | 
| 70 File files[] = directory.listFiles(); | 72 File files[] = directory.listFiles(); | 
| 71 for (File eachFile : files) | 73 for (File eachFile : files) | 
| 72 { | 74 { | 
| 73 delete(eachFile, true); | 75 delete(eachFile, true); | 
| 74 } | 76 } | 
| 75 | 77 | 
| 76 if (deleteSelf) | 78 if (deleteSelf) | 
| 77 { | 79 { | 
| 78 Log.w(TAG, "Deleting directory " + directory.getAbsolutePath()); | 80 Log.w(TAG, "Deleting directory " + directory.getAbsolutePath()); | 
| 79 directory.delete(); | 81 directory.delete(); | 
| 80 } | 82 } | 
| 81 } | 83 } | 
| 82 | 84 | 
| 83 public void deleteFile(File file) | 85 public static void deleteFile(File file) | 
| 84 { | 86 { | 
| 85 Log.w(TAG, "Deleting file " + file.getAbsolutePath()); | 87 Log.w(TAG, "Deleting file " + file.getAbsolutePath()); | 
| 86 file.delete(); | 88 file.delete(); | 
| 87 } | 89 } | 
| 88 } | 90 } | 
| 
diegocarloslima
2016/09/09 01:34:14
Since none of these methods retains any state for
 
anton
2016/09/09 06:50:53
Acknowledged.
 | |
| LEFT | RIGHT |