def open(fpath, oflags, mode=0666): """Open a file descript for a regular file in fpath using the open mode specifie by *oflag* with *mode*""" _oflags = FOFLAGS2OFLAGS.get(int(oflags), None) if oflags is None: raise ValueError("unknown file open mode: %r" % oflags) mode = int(mode) if not fcheck.mode_check(mode): raise ValueError("wrong mode: %r" % oct(mode)) fd = -1 try: fd = fcntl.open(fpath, _oflags, mode) if oflags in _FO_NEW_FLAGS \ else fcntl.open(fpath, _oflags) if oflags in _FO_NEW_FLAGS and not fcheck.ino_check(int(fd)): raise OSError("not enough free inodes") fd = File(fd) except: if fd > -1: unistd.close(fd) raise return fd
def open(fpath, oflag, mode=0666): """Open a file descript for a regular file in fpath using the open mode specifie by *oflag* with *mode*""" oflag = int(oflag) if oflag not in FO_MODES: raise ValueError("unknown file open mode: %r" % oflag) mode = int(mode) if not fcheck.mode_check(mode): raise ValueError("wrong mode: %r" % oct(mode)) fopen = _FOMODE2FUNC[oflag] fd = -1 try: fd = fopen(fpath, mode) fd = File(fd) if mode in _FO_NEW_MODES and not fcheck.ino_check(int(fd)): raise OSError("not enough free inodes") except: if fd > -1: os.close(fd) raise return fd