MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / downloadContent

Method downloadContent

src/Site/Site.py:156–268  ·  view source on GitHub ↗
(self, inner_path, download_files=True, peer=None, check_modifications=False, diffs={})

Source from the content-addressed store, hash-verified

154
155 # Download all file from content.json
156 def downloadContent(self, inner_path, download_files=True, peer=None, check_modifications=False, diffs={}):
157 s = time.time()
158 if config.verbose:
159 self.log.debug("Downloading %s..." % inner_path)
160
161 if not inner_path.endswith("content.json"):
162 return False
163
164 found = self.needFile(inner_path, update=self.bad_files.get(inner_path))
165 content_inner_dir = helper.getDirname(inner_path)
166 if not found:
167 self.log.debug("Download %s failed, check_modifications: %s" % (inner_path, check_modifications))
168 if check_modifications: # Download failed, but check modifications if its succed later
169 self.onFileDone.once(lambda file_name: self.checkModifications(0), "check_modifications")
170 return False # Could not download content.json
171
172 if config.verbose:
173 self.log.debug("Got %s" % inner_path)
174 changed, deleted = self.content_manager.loadContent(inner_path, load_includes=False)
175
176 if inner_path == "content.json":
177 self.saveSettings()
178
179 if peer: # Update last received update from peer to prevent re-sending the same update to it
180 peer.last_content_json_update = self.content_manager.contents[inner_path]["modified"]
181
182 # Start download files
183 file_threads = []
184 if download_files:
185 for file_relative_path in list(self.content_manager.contents[inner_path].get("files", {}).keys()):
186 file_inner_path = content_inner_dir + file_relative_path
187
188 # Try to diff first
189 diff_success = False
190 diff_actions = diffs.get(file_relative_path)
191 if diff_actions and self.bad_files.get(file_inner_path):
192 try:
193 s = time.time()
194 new_file = Diff.patch(self.storage.open(file_inner_path, "rb"), diff_actions)
195 new_file.seek(0)
196 time_diff = time.time() - s
197
198 s = time.time()
199 diff_success = self.content_manager.verifyFile(file_inner_path, new_file)
200 time_verify = time.time() - s
201
202 if diff_success:
203 s = time.time()
204 new_file.seek(0)
205 self.storage.write(file_inner_path, new_file)
206 time_write = time.time() - s
207
208 s = time.time()
209 self.onFileDone(file_inner_path)
210 time_on_done = time.time() - s
211
212 self.log.debug(
213 "Patched successfully: %s (diff: %.3fs, verify: %.3fs, write: %.3fs, on_done: %.3fs)" %

Callers 7

siteDownloadMethod · 0.95
downloadMethod · 0.95
needFileInfoMethod · 0.95
needFileMethod · 0.95
downloaderMethod · 0.80

Calls 13

needFileMethod · 0.95
checkModificationsMethod · 0.95
saveSettingsMethod · 0.95
isDownloadableMethod · 0.95
pooledNeedFileMethod · 0.95
onceMethod · 0.80
loadContentMethod · 0.80
openMethod · 0.80
getMethod · 0.45
seekMethod · 0.45
verifyFileMethod · 0.45
writeMethod · 0.45