Index: chrome/common/extensions/docs/server2/local_file_system.py |
diff --git a/chrome/common/extensions/docs/server2/local_file_system.py b/chrome/common/extensions/docs/server2/local_file_system.py |
index 7360e2a3cae1eced9e594db7c6b5a20bb82c86df..89dfd9faba4bc729f1ca0b787779379100b70f2c 100644 |
--- a/chrome/common/extensions/docs/server2/local_file_system.py |
+++ b/chrome/common/extensions/docs/server2/local_file_system.py |
@@ -18,16 +18,23 @@ class LocalFileSystem(file_system.FileSystem): |
return path.replace('/', os.sep) |
def _ReadFile(self, filename, binary): |
- with open(os.path.join(self._base_path, filename), 'r') as f: |
- contents = f.read() |
- if binary: |
- return contents |
- return file_system._ProcessFileData(contents, filename) |
+ try: |
+ with open(os.path.join(self._base_path, filename), 'r') as f: |
+ contents = f.read() |
+ if binary: |
+ return contents |
+ return file_system._ProcessFileData(contents, filename) |
+ except IOError: |
not at google - send to devlin
2012/08/10 06:12:16
why IOError here and OSError other times? Python q
cduvall
2012/08/10 17:25:16
Yep, os.listdir throws OSError, but open throws IO
|
+ raise file_system.FileNotFoundError(filename) |
def _ListDir(self, dir_name): |
all_files = [] |
full_path = os.path.join(self._base_path, dir_name) |
- for path in os.listdir(full_path): |
+ try: |
+ files = os.listdir(full_path) |
+ except OSError: |
+ raise file_system.FileNotFoundError(dir_name) |
+ for path in files: |
if path.startswith('.'): |
continue |
if os.path.isdir(os.path.join(full_path, path)): |
@@ -46,4 +53,9 @@ class LocalFileSystem(file_system.FileSystem): |
return Future(value=result) |
def Stat(self, path): |
- return self.StatInfo(os.stat(os.path.join(self._base_path, path)).st_mtime) |
+ try: |
+ return self.StatInfo( |
+ os.stat(os.path.join(self._base_path, path)).st_mtime) |
+ except OSError: |
+ raise file_system.FileNotFoundError(path) |
+ |