Don't remove missing optional files

This commit is contained in:
shortcutme 2017-01-27 12:02:14 +01:00
parent 0f0cf18f92
commit 697e177e13
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
4 changed files with 18 additions and 5 deletions

View File

@ -106,6 +106,7 @@ class Config(object):
action.add_argument('privatekey', help='Private key (default: ask on execute)', nargs='?')
action.add_argument('--inner_path', help='File you want to sign (default: content.json)',
default="content.json", metavar="inner_path")
action.add_argument('--remove_missing_optional', help='Remove optional files that is not present in the directory', action='store_true')
action.add_argument('--publish', help='Publish site after the signing', action='store_true')
# SitePublish

View File

@ -491,7 +491,7 @@ class ContentManager(object):
# Create and sign a content.json
# Return: The new content if filewrite = False
def sign(self, inner_path="content.json", privatekey=None, filewrite=True, update_changed_files=False, extend=None):
def sign(self, inner_path="content.json", privatekey=None, filewrite=True, update_changed_files=False, extend=None, remove_missing_optional=False):
if inner_path in self.contents:
content = self.contents[inner_path]
if self.contents[inner_path].get("cert_sign", False) is None and self.site.storage.isFile(inner_path):
@ -523,6 +523,11 @@ class ContentManager(object):
helper.getDirname(inner_path), content.get("ignore"), content.get("optional")
)
if not remove_missing_optional:
for file_inner_path, file_details in content.get("files_optional", {}).iteritems():
if file_inner_path not in files_optional_node:
files_optional_node[file_inner_path] = file_details
# Find changed files
files_merged = files_node.copy()
files_merged.update(files_optional_node)

View File

@ -287,7 +287,7 @@ class UiWebsocket(object):
self.response(to, ret)
# Sign content.json
def actionSiteSign(self, to, privatekey=None, inner_path="content.json", response_ok=True, update_changed_files=False):
def actionSiteSign(self, to, privatekey=None, inner_path="content.json", response_ok=True, update_changed_files=False, remove_missing_optional=False):
self.log.debug("Signing: %s" % inner_path)
site = self.site
extend = {} # Extended info for signing
@ -320,7 +320,7 @@ class UiWebsocket(object):
# Reload content.json, ignore errors to make it up-to-date
site.content_manager.loadContent(inner_path, add_bad_files=False, force=True)
# Sign using private key sent by user
signed = site.content_manager.sign(inner_path, privatekey, extend=extend, update_changed_files=update_changed_files)
signed = site.content_manager.sign(inner_path, privatekey, extend=extend, update_changed_files=update_changed_files, remove_missing_optional=remove_missing_optional)
if not signed:
self.cmd("notification", ["error", _["Content signing failed"]])
self.response(to, {"error": "Site sign failed"})
@ -469,6 +469,13 @@ class UiWebsocket(object):
):
return self.response(to, {"error": "Forbidden, you can only modify your own files"})
file_info = self.site.content_manager.getFileInfo(inner_path)
if file_info.get("optional"):
content_json = self.site_storage.loadJson(file_info["content_inner_path"])
if inner_path in content_json.get("files_optional", {}):
del content_json["files_optional"][inner_path]
self.site_storage.writeJson(content_json)
try:
self.site.storage.delete(inner_path)
except Exception, err:

View File

@ -188,7 +188,7 @@ class Actions(object):
logging.info("Site created!")
def siteSign(self, address, privatekey=None, inner_path="content.json", publish=False):
def siteSign(self, address, privatekey=None, inner_path="content.json", publish=False, remove_missing_optional=False):
from Site import Site
from Site import SiteManager
SiteManager.site_manager.load()
@ -208,7 +208,7 @@ class Actions(object):
import getpass
privatekey = getpass.getpass("Private key (input hidden):")
diffs = site.content_manager.getDiffs(inner_path)
succ = site.content_manager.sign(inner_path=inner_path, privatekey=privatekey, update_changed_files=True)
succ = site.content_manager.sign(inner_path=inner_path, privatekey=privatekey, update_changed_files=True, remove_missing_optional=remove_missing_optional)
if succ and publish:
self.sitePublish(address, inner_path=inner_path, diffs=diffs)