2 from zope.interface import implements
3 from twisted.internet import defer
4 from allmydata.interfaces import IFileNode, IFileURI, ICheckable
5 from allmydata.immutable.checker import SimpleCHKFileChecker, \
8 class ImmutableFileNode(object):
9 implements(IFileNode, ICheckable)
10 checker_class = SimpleCHKFileChecker
11 verifier_class = SimpleCHKFileVerifier
13 def __init__(self, uri, client):
14 self.u = IFileURI(uri)
17 def get_readonly_uri(self):
23 def is_readonly(self):
27 return self.u.__hash__()
28 def __eq__(self, other):
29 if IFileNode.providedBy(other):
30 return self.u.__eq__(other.u)
33 def __ne__(self, other):
34 if IFileNode.providedBy(other):
35 return self.u.__eq__(other.u)
39 class FileNode(ImmutableFileNode):
40 checker_class = SimpleCHKFileChecker
42 def __init__(self, uri, client):
43 ImmutableFileNode.__init__(self, uri, client)
46 return self.u.to_string()
49 return self.u.get_size()
51 def get_verifier(self):
52 return self.u.get_verifier()
54 def get_storage_index(self):
55 return self.u.storage_index
57 def check(self, verify=False):
58 storage_index = self.u.storage_index
59 k = self.u.needed_shares
60 N = self.u.total_shares
62 ueb_hash = self.u.uri_extension_hash
64 v = self.verifier_class(self._client,
65 storage_index, k, N, size, ueb_hash)
67 v = self.checker_class(self._client, storage_index, k, N)
70 def check_and_repair(self, verify=False):
71 # this is a stub, to allow the deep-check tests to pass.
72 #raise NotImplementedError("not implemented yet")
73 from allmydata.checker_results import CheckAndRepairResults
74 cr = CheckAndRepairResults(self.u.storage_index)
75 d = self.check(verify)
77 cr.pre_repair_results = cr.post_repair_results = r
78 cr.repair_attempted = False
83 def download(self, target):
84 downloader = self._client.getServiceNamed("downloader")
85 return downloader.download(self.get_uri(), target)
87 def download_to_data(self):
88 downloader = self._client.getServiceNamed("downloader")
89 return downloader.download_to_data(self.get_uri())
93 class LiteralFileNode(ImmutableFileNode):
95 def __init__(self, uri, client):
96 ImmutableFileNode.__init__(self, uri, client)
99 return self.u.to_string()
102 return len(self.u.data)
104 def get_verifier(self):
107 def get_storage_index(self):
110 def check(self, verify=False):
111 return defer.succeed(None)
113 def check_and_repair(self, verify=False):
114 return defer.succeed(None)
116 def download(self, target):
117 # note that this does not update the stats_provider
119 target.open(len(data))
122 return defer.maybeDeferred(target.finish)
124 def download_to_data(self):
126 return defer.succeed(data)