From ba0df239273f3b525002da00abb0050cc3b8e426 Mon Sep 17 00:00:00 2001 From: david-sarah <david-sarah@jacaranda.org> Date: Mon, 8 Aug 2011 18:02:04 +0000 Subject: [PATCH] node.py: tolerate a UTF-8 BOM at the start of tahoe.cfg. fixes #1470 --- src/allmydata/node.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 06b707de..a77fdadc 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -122,7 +122,21 @@ class Node(service.MultiService): def read_config(self): self.error_about_old_config_files() self.config = ConfigParser.SafeConfigParser() - self.config.read([os.path.join(self.basedir, "tahoe.cfg")]) + + tahoe_cfg = os.path.join(self.basedir, "tahoe.cfg") + try: + f = open(tahoe_cfg, "rb") + try: + # Skip any initial Byte Order Mark. Since this is an ordinary file, we + # don't need to handle incomplete reads, and can assume seekability. + if f.read(3) != '\xEF\xBB\xBF': + f.seek(0) + self.config.readfp(f) + finally: + f.close() + except EnvironmentError: + if os.path.exists(tahoe_cfg): + raise cfg_tubport = self.get_config("node", "tub.port", "") if not cfg_tubport: -- 2.45.2