diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2011-10-06 08:32:47 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2011-10-06 14:25:56 +0200 |
commit | a30b1b9ba549736f847040cd730fff6f326f78ac (patch) | |
tree | e637d0e6f6ba26502dfacaef34ac505c423f6c39 /main/src/cgeo/geocaching/cgData.java | |
parent | 5a7f82524734187904ec2bf898a1721be84cc882 (diff) | |
download | cgeo-a30b1b9ba549736f847040cd730fff6f326f78ac.zip cgeo-a30b1b9ba549736f847040cd730fff6f326f78ac.tar.gz cgeo-a30b1b9ba549736f847040cd730fff6f326f78ac.tar.bz2 |
Use an heuristic to find old cache directories to clean up
Using the heuristic will reduce the risk of removing a user directory
even though this storage area should be reserved for c:geo.
Diffstat (limited to 'main/src/cgeo/geocaching/cgData.java')
-rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 2da4343..9742d01 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -36,6 +36,7 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.regex.Pattern; public class cgData { @@ -955,18 +956,18 @@ public class cgData { createIndices(db); // Remove cache files corresponding to unknown caches + final Pattern oldFilePattern = Pattern.compile("^[GC|TB|O][A-Z0-9]{4,7}$"); final SQLiteStatement select = db.compileStatement("select count(*) from " + dbTableCaches + " where geocode = ?"); final File[] files = new File(Settings.getStorage()).listFiles(); final ArrayList<File> toRemove = new ArrayList<File>(files.length); for (final File file : files) { if (file.isDirectory()) { final String geocode = file.getName(); - if (geocode.equals("_others")) { - continue; - } - select.bindString(1, geocode); - if (select.simpleQueryForLong() == 0) { - toRemove.add(file); + if (oldFilePattern.matcher(geocode).find()) { + select.bindString(1, geocode); + if (select.simpleQueryForLong() == 0) { + toRemove.add(file); + } } } } |