mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
raise Exception, and check a filename is a regular file
This commit is contained in:
parent
cdfed3b349
commit
6a1520d5e4
1 changed files with 7 additions and 2 deletions
|
@ -208,12 +208,15 @@ class CommandsCache(cabc.Mapping):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fname = cmd0 if os.path.isabs(cmd0) else self.lazy_locate_binary(name)
|
fname = cmd0 if os.path.isabs(cmd0) else self.lazy_locate_binary(name)
|
||||||
|
|
||||||
if fname is None:
|
if fname is None:
|
||||||
return failure
|
return failure
|
||||||
|
if not os.path.isfile(fname):
|
||||||
|
return failure
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fd = os.open(fname, os.O_RDONLY | os.O_NONBLOCK)
|
fd = os.open(fname, os.O_RDONLY | os.O_NONBLOCK)
|
||||||
except:
|
except Exception:
|
||||||
return failure # opening error
|
return failure # opening error
|
||||||
|
|
||||||
search_for = {
|
search_for = {
|
||||||
|
@ -226,7 +229,9 @@ class CommandsCache(cabc.Mapping):
|
||||||
previous_block = block
|
previous_block = block
|
||||||
try:
|
try:
|
||||||
block = os.read(fd, 2048)
|
block = os.read(fd, 2048)
|
||||||
except: # e.g. IsADirectoryError
|
except Exception:
|
||||||
|
# should not occur, except e.g. if a file is deleted a a dir is
|
||||||
|
# created with the same name between os.path.isfile and os.open
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
return failure
|
return failure
|
||||||
if len(block) == 0:
|
if len(block) == 0:
|
||||||
|
|
Loading…
Add table
Reference in a new issue