1# Copyright 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from file_system import FileSystem, FileNotFoundError
6from future import Future
7
8
9class OfflineFileSystem(FileSystem):
10  '''An offline FileSystem which masquerades as another file system. It throws
11  FileNotFound error for all operations, and overrides GetIdentity.
12  '''
13  def __init__(self, fs):
14    self._fs = fs
15
16  def Read(self, paths, skip_not_found=False):
17    if skip_not_found: return Future(value={})
18    def raise_file_not_found():
19      raise FileNotFoundError('File system is offline, cannot read %s' % paths)
20    return Future(callback=raise_file_not_found)
21
22  def Stat(self, path):
23    raise FileNotFoundError('File system is offline, cannot read %s' % path)
24
25  def GetIdentity(self):
26    return self._fs.GetIdentity()
27