| 1025 | @flag.admin |
| 1026 | @flag.async_run |
| 1027 | def actionSiteListModifiedFiles(self, to, content_inner_path="content.json"): |
| 1028 | content = self.site.content_manager.contents[content_inner_path] |
| 1029 | min_mtime = content.get("modified", 0) |
| 1030 | site_path = self.site.storage.directory |
| 1031 | modified_files = [] |
| 1032 | |
| 1033 | # Load cache if not signed since last modified check |
| 1034 | if content.get("modified", 0) < self.site.settings["cache"].get("time_modified_files_check", 0): |
| 1035 | min_mtime = self.site.settings["cache"].get("time_modified_files_check") |
| 1036 | modified_files = self.site.settings["cache"].get("modified_files", []) |
| 1037 | |
| 1038 | inner_paths = [content_inner_path] + list(content.get("includes", {}).keys()) + list(content.get("files", {}).keys()) |
| 1039 | |
| 1040 | for relative_inner_path in inner_paths: |
| 1041 | inner_path = helper.getDirname(content_inner_path) + relative_inner_path |
| 1042 | try: |
| 1043 | is_mtime_newer = os.path.getmtime(self.site.storage.getPath(inner_path)) > min_mtime + 1 |
| 1044 | if is_mtime_newer: |
| 1045 | if inner_path.endswith("content.json"): |
| 1046 | is_modified = self.site.content_manager.isModified(inner_path) |
| 1047 | else: |
| 1048 | previous_size = content["files"][inner_path]["size"] |
| 1049 | is_same_size = self.site.storage.getSize(inner_path) == previous_size |
| 1050 | ext = inner_path.rsplit(".", 1)[-1] |
| 1051 | is_text_file = ext in ["json", "txt", "html", "js", "css"] |
| 1052 | if is_same_size: |
| 1053 | if is_text_file: |
| 1054 | is_modified = self.site.content_manager.isModified(inner_path) # Check sha512 hash |
| 1055 | else: |
| 1056 | is_modified = False |
| 1057 | else: |
| 1058 | is_modified = True |
| 1059 | |
| 1060 | # Check ran, modified back to original value, but in the cache |
| 1061 | if not is_modified and inner_path in modified_files: |
| 1062 | modified_files.remove(inner_path) |
| 1063 | else: |
| 1064 | is_modified = False |
| 1065 | except Exception as err: |
| 1066 | if not self.site.storage.isFile(inner_path): # File deleted |
| 1067 | is_modified = True |
| 1068 | else: |
| 1069 | raise err |
| 1070 | if is_modified and inner_path not in modified_files: |
| 1071 | modified_files.append(inner_path) |
| 1072 | |
| 1073 | self.site.settings["cache"]["time_modified_files_check"] = time.time() |
| 1074 | self.site.settings["cache"]["modified_files"] = modified_files |
| 1075 | return {"modified_files": modified_files} |
| 1076 | |
| 1077 | @flag.admin |
| 1078 | def actionSiteSetSettingsValue(self, to, key, value): |