Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b46db322 authored by Joël Stemmer's avatar Joël Stemmer
Browse files

Refactor include/exclude rules parsing

This pure refactor extracts parsing individual include/exclude tag
parsing into a separate function. A follow up change will introduce
parsing for a new tag. With this refactor that follow up change will be
easier to review.

Bug: 403956528
Test: atest FullBackupTest.java
Flag: EXEMPT refactor
Change-Id: I74f6fb06eafca9ccc24074689a3e25d8830ed067
parent fd0008b8
Loading
Loading
Loading
Loading
+87 −86
Original line number Diff line number Diff line
@@ -724,9 +724,20 @@ public class FullBackup {
            int event;
            while ((event = parser.next()) != XmlPullParser.END_DOCUMENT
                    && !parser.getName().equals(endingTag)) {
                switch (event) {
                    case XmlPullParser.START_TAG:
                if (event != XmlPullParser.START_TAG) {
                    continue;
                }
                validateInnerTagContents(parser);
                parseIncludeExcludeTag(parser, excludes, includes, maybeRequiredFlags);
            }
        }

        private void parseIncludeExcludeTag(
                XmlPullParser parser,
                Set<PathWithRequiredFlags> excludes,
                Map<String, Set<PathWithRequiredFlags>> includes,
                Optional<Integer> maybeRequiredFlags)
                throws XmlPullParserException, IOException {
            final String domainFromXml = parser.getAttributeValue(null, "domain");
            final File domainDirectory = getDirectoryForCriteriaDomain(domainFromXml);
            if (domainDirectory == null) {
@@ -740,13 +751,12 @@ public class FullBackup {
                                    + domainFromXml
                                    + "\" invalid; skipping");
                }
                            break;
                return;
            }
            final File canonicalFile =
                                extractCanonicalFile(
                                        domainDirectory, parser.getAttributeValue(null, "path"));
                    extractCanonicalFile(domainDirectory, parser.getAttributeValue(null, "path"));
            if (canonicalFile == null) {
                            break;
                return;
            }

            int requiredFlags = getRequiredFlagsForRule(parser, maybeRequiredFlags);
@@ -755,8 +765,7 @@ public class FullBackup {
            Set<PathWithRequiredFlags> activeSet =
                    parseCurrentTagForDomain(parser, excludes, includes, domainFromXml);
            activeSet.add(
                                new PathWithRequiredFlags(
                                        canonicalFile.getCanonicalPath(), requiredFlags));
                    new PathWithRequiredFlags(canonicalFile.getCanonicalPath(), requiredFlags));
            if (Log.isLoggable(TAG_XML_PARSER, Log.VERBOSE)) {
                Log.v(
                        TAG_XML_PARSER,
@@ -774,10 +783,8 @@ public class FullBackup {
            // exist). We have no way of knowing a priori whether or not to expect a
            // dir, so we add the -journal anyway to be safe.
            if ("database".equals(domainFromXml) && !canonicalFile.isDirectory()) {
                            final String canonicalJournalPath =
                                    canonicalFile.getCanonicalPath() + "-journal";
                            activeSet.add(
                                    new PathWithRequiredFlags(canonicalJournalPath, requiredFlags));
                final String canonicalJournalPath = canonicalFile.getCanonicalPath() + "-journal";
                activeSet.add(new PathWithRequiredFlags(canonicalJournalPath, requiredFlags));
                if (Log.isLoggable(TAG_XML_PARSER, Log.VERBOSE)) {
                    Log.v(
                            TAG_XML_PARSER,
@@ -785,10 +792,8 @@ public class FullBackup {
                                    + canonicalJournalPath
                                    + ". Ignore if nonexistent.");
                }
                            final String canonicalWalPath =
                                    canonicalFile.getCanonicalPath() + "-wal";
                            activeSet.add(
                                    new PathWithRequiredFlags(canonicalWalPath, requiredFlags));
                final String canonicalWalPath = canonicalFile.getCanonicalPath() + "-wal";
                activeSet.add(new PathWithRequiredFlags(canonicalWalPath, requiredFlags));
                if (Log.isLoggable(TAG_XML_PARSER, Log.VERBOSE)) {
                    Log.v(
                            TAG_XML_PARSER,
@@ -802,10 +807,8 @@ public class FullBackup {
            if ("sharedpref".equals(domainFromXml)
                    && !canonicalFile.isDirectory()
                    && !canonicalFile.getCanonicalPath().endsWith(".xml")) {
                            final String canonicalXmlPath =
                                    canonicalFile.getCanonicalPath() + ".xml";
                            activeSet.add(
                                    new PathWithRequiredFlags(canonicalXmlPath, requiredFlags));
                final String canonicalXmlPath = canonicalFile.getCanonicalPath() + ".xml";
                activeSet.add(new PathWithRequiredFlags(canonicalXmlPath, requiredFlags));
                if (Log.isLoggable(TAG_XML_PARSER, Log.VERBOSE)) {
                    Log.v(
                            TAG_XML_PARSER,
@@ -815,8 +818,6 @@ public class FullBackup {
                }
            }
        }
            }
        }

        private void logParsingResults(
                Set<PathWithRequiredFlags> excludes,