Removes file or directory, without raising exception if it doesn't exist. We assert-fail if the path still exists when we return, in case of permission problems etc.
(path)
| 251 | PYMUPDF_SETUP_SWIG = os.environ.get('PYMUPDF_SETUP_SWIG') |
| 252 | |
| 253 | def _fs_remove(path): |
| 254 | ''' |
| 255 | Removes file or directory, without raising exception if it doesn't exist. |
| 256 | |
| 257 | We assert-fail if the path still exists when we return, in case of |
| 258 | permission problems etc. |
| 259 | ''' |
| 260 | # First try deleting `path` as a file. |
| 261 | try: |
| 262 | os.remove( path) |
| 263 | except Exception as e: |
| 264 | pass |
| 265 | |
| 266 | if os.path.exists(path): |
| 267 | # Try deleting `path` as a directory. Need to use |
| 268 | # shutil.rmtree() callback to handle permission problems; see: |
| 269 | # https://docs.python.org/3/library/shutil.html#rmtree-example |
| 270 | # |
| 271 | def error_fn(fn, path, excinfo): |
| 272 | # Clear the readonly bit and reattempt the removal. |
| 273 | os.chmod(path, stat.S_IWRITE) |
| 274 | fn(path) |
| 275 | shutil.rmtree( path, onerror=error_fn) |
| 276 | |
| 277 | assert not os.path.exists( path) |
| 278 | |
| 279 | |
| 280 | def _git_get_branch( directory): |
no test coverage detected
searching dependent graphs…