MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / _fs_remove

Function _fs_remove

setup.py:253–277  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

251PYMUPDF_SETUP_SWIG = os.environ.get('PYMUPDF_SETUP_SWIG')
252
253def _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
280def _git_get_branch( directory):

Callers 1

get_mupdf_internalFunction · 0.85

Calls 1

removeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…