commit 21e6b839918e88f8260a58b23614194ec1230247 Author: Arturo Filastò <art...@filasto.net> Date: Fri Aug 5 17:16:50 2016 +0200
ignoreExistingDirectory is a recent twisted thing. Wrap calls to makedirs with proper exception handling. --- ooni/deck/store.py | 13 +++++++++++-- ooni/resources.py | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ooni/deck/store.py b/ooni/deck/store.py index 2d24f29..295f817 100644 --- a/ooni/deck/store.py +++ b/ooni/deck/store.py @@ -1,5 +1,6 @@ import csv import json +import errno from copy import deepcopy from twisted.internet import defer @@ -76,8 +77,16 @@ class InputStore(object): self.path = FilePath(config.inputs_directory) self.resources = FilePath(config.resources_directory) - self.path.child("descriptors").makedirs(ignoreExistingDirectory=True) - self.path.child("data").makedirs(ignoreExistingDirectory=True) + try: + self.path.child("descriptors").makedirs() + except OSError as e: + if not e.errno == errno.EEXIST: + raise + try: + self.path.child("data").makedirs() + except OSError as e: + if not e.errno == errno.EEXIST: + raise yield self.update_url_lists(country_code) @defer.inlineCallbacks diff --git a/ooni/resources.py b/ooni/resources.py index 9615c53..f97616c 100644 --- a/ooni/resources.py +++ b/ooni/resources.py @@ -1,4 +1,5 @@ import json +import errno from twisted.python.filepath import FilePath from twisted.internet import defer @@ -107,7 +108,11 @@ def check_for_update(country_code=None): latest_version = yield get_latest_version() resources_dir = FilePath(config.resources_directory) - resources_dir.makedirs(ignoreExistingDirectory=True) + try: + resources_dir.makedirs() + except OSError as e: + if not e.errno == errno.EEXIST: + raise current_manifest = resources_dir.child("manifest.json") if current_manifest.exists(): @@ -149,7 +154,11 @@ def check_for_update(country_code=None): filename = filename[:-3] gzipped = True dst_file = resources_dir.child(pre_path).child(filename) - dst_file.parent().makedirs(ignoreExistingDirectory=True) + try: + dst_file.parent().makedirs() + except OSError as e: + if not e.errno == errno.EEXIST: + raise src_file = dst_file.temporarySibling() src_file.alwaysCreate = 0
_______________________________________________ tor-commits mailing list tor-commits@lists.torproject.org https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits