config/rebuild_check.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 # This Source Code Form is subject to the terms of the Mozilla Public
     2 # License, v. 2.0. If a copy of the MPL was not distributed with this
     3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     5 import os
     6 import errno
     8 def mtime(path):
     9     try:
    10         return os.stat(path).st_mtime
    11     except OSError as e:
    12         if e.errno == errno.ENOENT:
    13             return -1
    14         raise
    16 def rebuild_check(args):
    17     target = args[0]
    18     deps = args[1:]
    19     t = mtime(target)
    20     if t < 0:
    21         print target
    22         return
    24     newer = []
    25     removed = []
    26     for dep in deps:
    27         deptime = mtime(dep)
    28         if deptime < 0:
    29             removed.append(dep)
    30         elif mtime(dep) > t:
    31             newer.append(dep)
    33     if newer and removed:
    34         print 'Rebuilding %s because %s changed and %s was removed' % (target, ', '.join(newer), ', '.join(removed))
    35     elif newer:
    36         print 'Rebuilding %s because %s changed' % (target, ', '.join(newer))
    37     elif removed:
    38         print 'Rebuilding %s because %s was removed' % (target, ', '.join(removed))
    39     else:
    40         print 'Rebuilding %s for an unknown reason' % target
    42 if __name__ == '__main__':
    43     import sys
    44     rebuild_check(sys.argv[1:])

mercurial