Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Unified Diff: chrome/common/extensions/docs/server2/local_file_system.py

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, redirect fix Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 2955d8c64b35149635862a059850a49270213674..8a6aae41125265ccc439b95959fd9f0e5823d621 100644
--- a/chrome/common/extensions/docs/server2/local_file_system.py
+++ b/chrome/common/extensions/docs/server2/local_file_system.py
@@ -3,19 +3,25 @@
# found in the LICENSE file.
import os
+import sys
+from docs_server_utils import StringIdentity
from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode
from future import Future
+def _ConvertToFilepath(path):
+ return path.replace('/', os.sep)
+
class LocalFileSystem(FileSystem):
- """FileSystem implementation which fetches resources from the local
+ '''FileSystem implementation which fetches resources from the local
filesystem.
- """
+ '''
def __init__(self, base_path):
- self._base_path = self._ConvertToFilepath(base_path)
+ self._base_path = _ConvertToFilepath(base_path)
- def _ConvertToFilepath(self, path):
- return path.replace('/', os.sep)
+ @staticmethod
+ def Create():
+ return LocalFileSystem(os.path.join(sys.path[0], os.pardir, os.pardir))
def _ReadFile(self, filename, binary):
try:
@@ -48,21 +54,31 @@ class LocalFileSystem(FileSystem):
result = {}
for path in paths:
if path.endswith('/'):
- result[path] = self._ListDir(self._ConvertToFilepath(path))
+ result[path] = self._ListDir(_ConvertToFilepath(path))
else:
- result[path] = self._ReadFile(self._ConvertToFilepath(path), binary)
+ result[path] = self._ReadFile(_ConvertToFilepath(path), binary)
return Future(value=result)
def _CreateStatInfo(self, path):
- if path.endswith('/'):
- versions = dict((filename, os.stat(os.path.join(path, filename)).st_mtime)
- for filename in os.listdir(path))
- else:
- versions = None
try:
- return StatInfo(os.stat(path).st_mtime, versions)
+ path_mtime = os.stat(path).st_mtime
+ if path.endswith('/'):
+ child_versions = dict(
+ (filename, os.stat(os.path.join(path, filename)).st_mtime)
+ for filename in os.listdir(path))
+ # This file system stat mimics subversion, where the stat of directories
+ # is max(file stats). That means we need to recursively check the whole
+ # file system tree :\ so approximate that by just checking this dir.
+ version = max([path_mtime] + child_versions.values())
+ else:
+ child_versions = None
+ version = path_mtime
+ return StatInfo(version, child_versions)
except OSError as e:
raise FileNotFoundError('os.stat failed for %s: %s' % (path, e))
def Stat(self, path):
return self._CreateStatInfo(os.path.join(self._base_path, path))
+
+ def GetIdentity(self):
+ return '@'.join((self.__class__.__name__, StringIdentity(self._base_path)))

Powered by Google App Engine
This is Rietveld 408576698