Trying to make LocalRepo stuff have less subtle side effects.

I had trouble wrapping my head around which point in time the fdroid/repo
directories are created, when they are populated with .html files, and
when the index.xml is put there. I did some minor cleaning up to make
it a bit easier to manage this in the future.
This commit is contained in:
Peter Serwylo 2015-03-05 22:54:09 +11:00
parent 20f17da913
commit 842ddb5e24

View File

@ -81,7 +81,9 @@ public class LocalRepoManager {
private SanitizedFile xmlIndexJarUnsigned = null; private SanitizedFile xmlIndexJarUnsigned = null;
public final SanitizedFile webRoot; public final SanitizedFile webRoot;
public final SanitizedFile fdroidDir; public final SanitizedFile fdroidDir;
public final SanitizedFile fdroidDirCaps;
public final SanitizedFile repoDir; public final SanitizedFile repoDir;
public final SanitizedFile repoDirCaps;
public final SanitizedFile iconsDir; public final SanitizedFile iconsDir;
@Nullable @Nullable
@ -103,7 +105,9 @@ public class LocalRepoManager {
webRoot = SanitizedFile.knownSanitized(c.getFilesDir()); webRoot = SanitizedFile.knownSanitized(c.getFilesDir());
/* /fdroid/repo is the standard path for user repos */ /* /fdroid/repo is the standard path for user repos */
fdroidDir = new SanitizedFile(webRoot, "fdroid"); fdroidDir = new SanitizedFile(webRoot, "fdroid");
fdroidDirCaps = new SanitizedFile(webRoot, "FDROID");
repoDir = new SanitizedFile(fdroidDir, "repo"); repoDir = new SanitizedFile(fdroidDir, "repo");
repoDirCaps = new SanitizedFile(fdroidDirCaps, "REPO");
iconsDir = new SanitizedFile(repoDir, "icons"); iconsDir = new SanitizedFile(repoDir, "icons");
xmlIndex = new SanitizedFile(repoDir, "index.xml"); xmlIndex = new SanitizedFile(repoDir, "index.xml");
xmlIndexJar = new SanitizedFile(repoDir, "index.jar"); xmlIndexJar = new SanitizedFile(repoDir, "index.jar");
@ -163,18 +167,15 @@ public class LocalRepoManager {
// make symlinks/copies in each subdir of the repo to make sure that // make symlinks/copies in each subdir of the repo to make sure that
// the user will always find the bootstrap page. // the user will always find the bootstrap page.
symlinkIndexPageElsewhere("../", fdroidDir); symlinkEntireWebRootElsewhere("../", fdroidDir);
symlinkIndexPageElsewhere("../../", repoDir); symlinkEntireWebRootElsewhere("../../", repoDir);
// add in /FDROID/REPO to support bad QR Scanner apps // add in /FDROID/REPO to support bad QR Scanner apps
File fdroidCAPS = new File(fdroidDir.getParentFile(), "FDROID"); attemptToMkdir(fdroidDirCaps);
attemptToMkdir(fdroidCAPS); attemptToMkdir(repoDirCaps);
File repoCAPS = new File(fdroidCAPS, "REPO"); symlinkEntireWebRootElsewhere("../", fdroidDirCaps);
attemptToMkdir(repoCAPS); symlinkEntireWebRootElsewhere("../../", repoDirCaps);
symlinkIndexPageElsewhere("../", fdroidCAPS);
symlinkIndexPageElsewhere("../../", repoCAPS);
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error writing local repo index: " + e.getMessage()); Log.e(TAG, "Error writing local repo index: " + e.getMessage());
@ -192,28 +193,29 @@ public class LocalRepoManager {
} }
if (!dir.mkdir()) { if (!dir.mkdir()) {
throw new IOException("An error occured trying to create directory " + dir); throw new IOException("An error occurred trying to create directory " + dir);
} }
} }
private static void attemptToDelete(File file) { private static void attemptToDelete(@NonNull File file) {
if (!file.delete()) { if (!file.delete()) {
Log.e(TAG, "Could not delete \"" + file.getAbsolutePath() + "\"."); Log.e(TAG, "Could not delete \"" + file.getAbsolutePath() + "\".");
} }
} }
private void symlinkIndexPageElsewhere(String symlinkPrefix, File directory) { private void symlinkEntireWebRootElsewhere(String symlinkPrefix, File directory) {
SanitizedFile index = new SanitizedFile(directory, "index.html"); symlinkFileElsewhere("index.html", symlinkPrefix, directory);
attemptToDelete(index);
Utils.symlinkOrCopyFile(new SanitizedFile(new File(directory, symlinkPrefix), "index.html"), index);
for(String fileName : WEB_ROOT_ASSET_FILES) { for(String fileName : WEB_ROOT_ASSET_FILES) {
SanitizedFile file = new SanitizedFile(directory, fileName); symlinkFileElsewhere(fileName, symlinkPrefix, directory);
attemptToDelete(file);
Utils.symlinkOrCopyFile(new SanitizedFile(new File(directory, symlinkPrefix), fileName), file);
} }
} }
private void symlinkFileElsewhere(String fileName, String symlinkPrefix, File directory) {
SanitizedFile index = new SanitizedFile(directory, fileName);
attemptToDelete(index);
Utils.symlinkOrCopyFile(new SanitizedFile(new File(directory, symlinkPrefix), fileName), index);
}
private void deleteContents(File path) { private void deleteContents(File path) {
if (path.exists()) { if (path.exists()) {
for (File file : path.listFiles()) { for (File file : path.listFiles()) {
@ -441,6 +443,7 @@ public class LocalRepoManager {
private void tagApplication(App app) throws IOException { private void tagApplication(App app) throws IOException {
serializer.startTag("", "application"); serializer.startTag("", "application");
serializer.attribute("", "id", app.id);
tag("id", app.id); tag("id", app.id);
tag("added", app.added); tag("added", app.added);