update dotfile from file pointed by path
(self, path, dotfile)
| 92 | return self._update(path, dotfile) |
| 93 | |
| 94 | def _update(self, path, dotfile): |
| 95 | """update dotfile from file pointed by path""" |
| 96 | ret = False |
| 97 | new_path = None |
| 98 | ignores = list(set(self.ignore + dotfile.upignore)) |
| 99 | prefixes = [dotfile.dst, dotfile.src] |
| 100 | ignores = ignores_to_absolute(ignores, prefixes, |
| 101 | debug=self.debug) |
| 102 | self.log.dbg(f'ignore pattern(s) for {path}: {ignores}') |
| 103 | |
| 104 | deployed_path = os.path.expanduser(path) |
| 105 | local_path = os.path.join(self.dotpath, dotfile.src) |
| 106 | local_path = os.path.expanduser(local_path) |
| 107 | |
| 108 | if not os.path.exists(deployed_path): |
| 109 | msg = f'\"{deployed_path}\" does not exist' |
| 110 | self.log.err(msg) |
| 111 | return False |
| 112 | |
| 113 | if not os.path.exists(local_path): |
| 114 | msg = f'\"{local_path}\" does not exist, import it first' |
| 115 | self.log.err(msg) |
| 116 | return False |
| 117 | |
| 118 | ignore_missing_in_dotdrop = self.ignore_missing_in_dotdrop or \ |
| 119 | dotfile.ignore_missing_in_dotdrop |
| 120 | |
| 121 | if ignore_missing_in_dotdrop and not os.path.exists(local_path): |
| 122 | self.log.sub(f'\"{dotfile.key}\" ignored') |
| 123 | return True |
| 124 | |
| 125 | # apply write transformation if any |
| 126 | new_path = self._apply_trans_update(deployed_path, dotfile) |
| 127 | if not new_path: |
| 128 | return False |
| 129 | |
| 130 | # save current rights |
| 131 | deployed_mode = get_file_perm(deployed_path) |
| 132 | local_mode = get_file_perm(local_path) |
| 133 | |
| 134 | # handle the pointed file |
| 135 | if os.path.isdir(new_path): |
| 136 | ret = self._handle_dir(new_path, local_path, |
| 137 | dotfile, ignores) |
| 138 | else: |
| 139 | ret = self._handle_file(new_path, local_path, |
| 140 | ignores) |
| 141 | if not ret: |
| 142 | return False |
| 143 | |
| 144 | # mirror rights |
| 145 | if deployed_mode != local_mode: |
| 146 | msg = f'adopt mode {deployed_mode:o} for {dotfile.key}' |
| 147 | self.log.dbg(msg) |
| 148 | if self.conf.update_dotfile(dotfile.key, deployed_mode): |
| 149 | ret = True |
| 150 | self._mirror_file_perms(deployed_path, local_path) |
| 151 |
no test coverage detected