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

Method getFileInfo

src/Content/ContentManager.py:402–457  ·  view source on GitHub ↗
(self, inner_path, new_file=False)

Source from the content-addressed store, hash-verified

400 # Find the file info line from self.contents
401 # Return: { "sha512": "c29d73d...21f518", "size": 41 , "content_inner_path": "content.json"}
402 def getFileInfo(self, inner_path, new_file=False):
403 dirs = inner_path.split("/") # Parent dirs of content.json
404 inner_path_parts = [dirs.pop()] # Filename relative to content.json
405 while True:
406 content_inner_path = "%s/content.json" % "/".join(dirs)
407 content_inner_path = content_inner_path.strip("/")
408 content = self.contents.get(content_inner_path)
409
410 # Check in files
411 if content and "files" in content:
412 back = content["files"].get("/".join(inner_path_parts))
413 if back:
414 back["content_inner_path"] = content_inner_path
415 back["optional"] = False
416 back["relative_path"] = "/".join(inner_path_parts)
417 return back
418
419 # Check in optional files
420 if content and "files_optional" in content: # Check if file in this content.json
421 back = content["files_optional"].get("/".join(inner_path_parts))
422 if back:
423 back["content_inner_path"] = content_inner_path
424 back["optional"] = True
425 back["relative_path"] = "/".join(inner_path_parts)
426 return back
427
428 # Return the rules if user dir
429 if content and "user_contents" in content:
430 back = content["user_contents"]
431 content_inner_path_dir = helper.getDirname(content_inner_path)
432 relative_content_path = inner_path[len(content_inner_path_dir):]
433 user_auth_address_match = re.match(r"([A-Za-z0-9]+)/.*", relative_content_path)
434 if user_auth_address_match:
435 user_auth_address = user_auth_address_match.group(1)
436 back["content_inner_path"] = "%s%s/content.json" % (content_inner_path_dir, user_auth_address)
437 else:
438 back["content_inner_path"] = content_inner_path_dir + "content.json"
439 back["optional"] = None
440 back["relative_path"] = "/".join(inner_path_parts)
441 return back
442
443 if new_file and content:
444 back = {}
445 back["content_inner_path"] = content_inner_path
446 back["relative_path"] = "/".join(inner_path_parts)
447 back["optional"] = None
448 return back
449
450 # No inner path in this dir, lets try the parent dir
451 if dirs:
452 inner_path_parts.insert(0, dirs.pop())
453 else: # No more parent dirs
454 break
455
456 # Not found
457 return False
458
459 # Get rules for the file

Callers 13

isArchivedMethod · 0.95
isDownloadedMethod · 0.95
getRulesMethod · 0.95
verifyFileMethod · 0.95
actionSiteSignMethod · 0.45
actionFileDeleteMethod · 0.45
checkBadFilesMethod · 0.45
needFileInfoMethod · 0.45
addTaskMethod · 0.45
testSignersMethod · 0.45
testFileInfoMethod · 0.45
testOptionalDownloadMethod · 0.45

Calls 1

getMethod · 0.45

Tested by 4

testSignersMethod · 0.36
testFileInfoMethod · 0.36
testOptionalDownloadMethod · 0.36
testFindOptionalMethod · 0.36