| 142 | |
| 143 | |
| 144 | def _path_diagnostic(path): |
| 145 | # type: (Text) -> Text |
| 146 | |
| 147 | path_type = "<unknown path type>" |
| 148 | if os.path.isdir(path): |
| 149 | path_type = "dir" |
| 150 | elif os.path.isfile(path): |
| 151 | path_type = "file" |
| 152 | |
| 153 | try: |
| 154 | os_stat = os.stat(path) |
| 155 | |
| 156 | mode = oct(os_stat.st_mode) |
| 157 | if hasattr(stat, "filemode"): |
| 158 | mode = "{mode} ({human_mode})".format( |
| 159 | mode=mode, human_mode=stat.filemode(os_stat.st_mode) # type: ignore[attr-defined] |
| 160 | ) |
| 161 | |
| 162 | return ( |
| 163 | "{path_type} ok? {path!r}:\n" |
| 164 | " mode: {mode} owner: {uid} group: {gid}\n" |
| 165 | " {stat}".format( |
| 166 | path_type=path_type, |
| 167 | path=path, |
| 168 | mode=mode, |
| 169 | uid=os_stat.st_uid, |
| 170 | gid=os_stat.st_gid, |
| 171 | stat=os_stat, |
| 172 | ) |
| 173 | ) |
| 174 | except OSError as e: |
| 175 | return "{path_type} err {path!r}:\n {err}".format(path_type=path_type, path=path, err=e) |
| 176 | |
| 177 | |
| 178 | def safe_copy(source, dest, overwrite=False): |