config/createprecomplete.py

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 # Any copyright is dedicated to the Public Domain.
     2 # http://creativecommons.org/publicdomain/zero/1.0/
     4 # Creates the precomplete file containing the remove and rmdir application
     5 # update instructions which is used to remove files and directories that are no
     6 # longer present in a complete update. The current working directory is used for
     7 # the location to enumerate and to create the precomplete file.
     8 # For symlinks, remove instructions are always generated.
    10 import sys
    11 import os
    13 def get_build_entries(root_path):
    14     """ Iterates through the root_path, creating a list for each file and
    15         directory. Excludes any file paths ending with channel-prefs.js.
    16         To support Tor Browser updates, excludes:
    17           TorBrowser/Data/Browser/profiles.ini
    18           TorBrowser/Data/Browser/profile.default/bookmarks.html
    19           TorBrowser/Data/Tor/torrc
    20     """
    21     rel_file_path_set = set()
    22     rel_dir_path_set = set()
    23     for root, dirs, files in os.walk(root_path):
    24         for file_name in files:
    25             parent_dir_rel_path = root[len(root_path)+1:]
    26             rel_path_file = os.path.join(parent_dir_rel_path, file_name)
    27             rel_path_file = rel_path_file.replace("\\", "/")
    28             if not (rel_path_file.endswith("channel-prefs.js") or
    29                     rel_path_file.endswith("update-settings.ini") or
    30                     rel_path_file == "TorBrowser/Data/Browser/profiles.ini" or
    31                     rel_path_file == "TorBrowser/Data/Browser/profile.default/bookmarks.html" or
    32                     rel_path_file == "TorBrowser/Data/Tor/torrc" or
    33                     rel_path_file.find("distribution/") != -1):
    34                 rel_file_path_set.add(rel_path_file)
    36         for dir_name in dirs:
    37             parent_dir_rel_path = root[len(root_path)+1:]
    38             rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
    39             rel_path_dir = rel_path_dir.replace("\\", "/")+"/"
    40             if rel_path_dir.find("distribution/") == -1:
    41                 if (os.path.islink(rel_path_dir[:-1])):
    42                     rel_file_path_set.add(rel_path_dir[:-1])
    43                 else:
    44                     rel_dir_path_set.add(rel_path_dir)
    46     rel_file_path_list = list(rel_file_path_set)
    47     rel_file_path_list.sort(reverse=True)
    48     rel_dir_path_list = list(rel_dir_path_set)
    49     rel_dir_path_list.sort(reverse=True)
    51     return rel_file_path_list, rel_dir_path_list
    53 def generate_precomplete(root_path):
    54     """ Creates the precomplete file containing the remove and rmdir
    55         application update instructions. The given directory is used
    56         for the location to enumerate and to create the precomplete file.
    57     """
    58     # If inside a Mac bundle use the root of the bundle for the path.
    59     if os.path.basename(root_path) == "MacOS":
    60         root_path = os.path.abspath(os.path.join(root_path, '../../'))
    62     rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
    63     precomplete_file_path = os.path.join(root_path,"precomplete")
    64     # open in binary mode to prevent OS specific line endings.
    65     precomplete_file = open(precomplete_file_path, "wb")
    66     for rel_file_path in rel_file_path_list:
    67         precomplete_file.writelines("remove \""+rel_file_path+"\"\n")
    69     for rel_dir_path in rel_dir_path_list:
    70         precomplete_file.writelines("rmdir \""+rel_dir_path+"\"\n")
    72     precomplete_file.close()
    74 if __name__ == "__main__":
    75     generate_precomplete(os.getcwd())

mercurial