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.

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

mercurial