Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java

Issue 29347192: Issue 4181 - Fix FilterEngineTest tests (Closed)
Patch Set: Changes with applied Eyeo's codestyle (2-space indentation) Created Aug. 8, 2016, 7:51 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..b92d693e7b8adfa5745f1fdfce75d5a3a568d8ef
--- /dev/null
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/FileSystemUtils.java
@@ -0,0 +1,88 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2016 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.adblockplus.libadblockplus;
+
+import android.util.Log;
+
+import java.io.File;
+import java.util.UUID;
+
+public class FileSystemUtils
anton 2016/08/08 07:52:51 also renamed FileSystemHelper to FileSystemUtils t
+{
+ private static final String TAG = FileSystemUtils.class.getSimpleName();
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.
+
+ // File.createTempFile() creates a file instead of just generating unique file name
+
+ public String generateUniqueFileName(String prefix, String suffix)
+ {
+ StringBuilder sb = new StringBuilder();
+ if (prefix != null)
+ {
+ sb.append(prefix);
+ }
+ sb.append(UUID.randomUUID());
+ if (suffix != null)
+ {
+ sb.append(suffix);
+ }
+ return sb.toString();
+ }
+
+ public File generateUniqueFileName(String prefix, String suffix, File parent)
+ {
+ return new File(parent, generateUniqueFileName(prefix, suffix));
+ }
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.
+
+ public void delete(String filePath, boolean deleteSelf)
+ {
+ delete(new File(filePath), deleteSelf);
+ }
+
+ public void delete(File file, boolean deleteSelf)
+ {
+ if (file.isDirectory())
+ {
+ deleteDirectory(file, deleteSelf);
+ }
+ else
+ {
+ deleteFile(file);
+ }
+ }
+
+ public void deleteDirectory(File directory, boolean deleteSelf)
+ {
+ File files[] = directory.listFiles();
+ for (File eachFile : files)
+ {
+ delete(eachFile, true);
+ }
+
+ if (deleteSelf)
+ {
+ Log.w(TAG, "Deleting directory " + directory.getAbsolutePath());
+ directory.delete();
+ }
+ }
+
+ public void deleteFile(File file)
+ {
+ Log.w(TAG, "Deleting file " + file.getAbsolutePath());
+ file.delete();
+ }
+}
diegocarloslima 2016/09/09 01:34:14 Since none of these methods retains any state for
anton 2016/09/09 06:50:53 Acknowledged.
« no previous file with comments | « no previous file | libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld