Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

node.py: tolerate a UTF-8 BOM at the start of tahoe.cfg. fixes #1470

  • Loading branch information...
commit ba0df239273f3b525002da00abb0050cc3b8e426 1 parent 87ca4fc
Daira Hopwood authored

Showing 1 changed file with 15 additions and 1 deletion. Show diff stats Hide diff stats

  1. 16  src/allmydata/node.py
16  src/allmydata/node.py
@@ -122,7 +122,21 @@ def set_config(self, section, option, value):
122 122
     def read_config(self):
123 123
         self.error_about_old_config_files()
124 124
         self.config = ConfigParser.SafeConfigParser()
125  
-        self.config.read([os.path.join(self.basedir, "tahoe.cfg")])
  125
+
  126
+        tahoe_cfg = os.path.join(self.basedir, "tahoe.cfg")
  127
+        try:
  128
+            f = open(tahoe_cfg, "rb")
  129
+            try:
  130
+                # Skip any initial Byte Order Mark. Since this is an ordinary file, we
  131
+                # don't need to handle incomplete reads, and can assume seekability.
  132
+                if f.read(3) != '\xEF\xBB\xBF':
  133
+                    f.seek(0)
  134
+                self.config.readfp(f)
  135
+            finally:
  136
+                f.close()
  137
+        except EnvironmentError:
  138
+            if os.path.exists(tahoe_cfg):
  139
+                raise
126 140
 
127 141
         cfg_tubport = self.get_config("node", "tub.port", "")
128 142
         if not cfg_tubport:

0 notes on commit ba0df23

Please sign in to comment.
Something went wrong with that request. Please try again.