diff --git a/src/Site/Site.py b/src/Site/Site.py index d2527a79..ff9e446d 100644 --- a/src/Site/Site.py +++ b/src/Site/Site.py @@ -522,7 +522,7 @@ class Site(object): return len(published) # Copy this site - def clone(self, address, privatekey=None, address_index=None, overwrite=False): + def clone(self, address, privatekey=None, address_index=None, root_inner_path="", overwrite=False): import shutil new_site = SiteManager.site_manager.need(address, all_file=False) default_dirs = [] # Dont copy these directories (has -default version) @@ -530,7 +530,7 @@ class Site(object): if "-default" in dir_name: default_dirs.append(dir_name.replace("-default", "")) - self.log.debug("Cloning to %s, ignore dirs: %s" % (address, default_dirs)) + self.log.debug("Cloning to %s, ignore dirs: %s, root: %s" % (address, default_dirs, root_inner_path)) # Copy root content.json if not new_site.storage.isFile("content.json") and not overwrite: @@ -540,6 +540,7 @@ class Site(object): del content_json["domain"] content_json["title"] = "my" + content_json["title"] content_json["cloned_from"] = self.address + content_json["clone_root"] = root_inner_path content_json["files"] = {} if address_index: content_json["address_index"] = address_index # Site owner's BIP32 index @@ -553,13 +554,21 @@ class Site(object): for file_relative_path in sorted(content["files"].keys()): file_inner_path = helper.getDirname(content_inner_path) + file_relative_path # Relative to content.json file_inner_path = file_inner_path.strip("/") # Strip leading / + if not file_inner_path.startswith(root_inner_path): + self.log.debug("[SKIP] %s (not in clone root)" % file_inner_path) + continue if file_inner_path.split("/")[0] in default_dirs: # Dont copy directories that has -default postfixed alternative self.log.debug("[SKIP] %s (has default alternative)" % file_inner_path) continue file_path = self.storage.getPath(file_inner_path) # Copy the file normally to keep the -default postfixed dir and file to allow cloning later - file_path_dest = new_site.storage.getPath(file_inner_path) + if root_inner_path: + file_inner_path_dest = re.sub("^%s" % re.escape(root_inner_path), "", file_inner_path) + file_path_dest = new_site.storage.getPath(file_inner_path_dest) + else: + file_path_dest = new_site.storage.getPath(file_inner_path) + self.log.debug("[COPY] %s to %s..." % (file_inner_path, file_path_dest)) dest_dir = os.path.dirname(file_path_dest) if not os.path.isdir(dest_dir): diff --git a/src/Ui/UiWebsocket.py b/src/Ui/UiWebsocket.py index d212bd5f..9a1b239f 100644 --- a/src/Ui/UiWebsocket.py +++ b/src/Ui/UiWebsocket.py @@ -681,12 +681,12 @@ class UiWebsocket(object): else: self.response(to, {"error": "Unknown site: %s" % address}) - def actionSiteClone(self, to, address): + def actionSiteClone(self, to, address, root_inner_path=""): self.cmd("notification", ["info", "Cloning site..."]) site = self.server.sites.get(address) # Generate a new site from user's bip32 seed new_address, new_address_index, new_site_data = self.user.getNewSiteData() - new_site = site.clone(new_address, new_site_data["privatekey"], address_index=new_address_index) + new_site = site.clone(new_address, new_site_data["privatekey"], address_index=new_address_index, root_inner_path=root_inner_path) new_site.settings["own"] = True new_site.saveSettings() self.cmd("notification", ["done", _["Site cloned"] + "" % new_address])