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.

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

mercurial