Example #1
0
 def touch(fpath, mode=0666):
     """Create a new file with passed *mode* in *fpath*.
     If file *fpath* exists, a IOError will be raised."""
     mode = int(mode)
     if not fcheck.mode_check(mode):
         raise ValueError("wrong mode: %r" % oct(mode))
     fd = -1
     try:
         fd = fcntl.open(fpath, fcntl.O_RDONLY | fcntl.O_CREAT, mode)
     finally:
         if fd >= 0:
             unistd.close(fd)
Example #2
0
 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
Example #3
0
 def touch(fpath, mode=0666):
     """Create a new file with passed *mode* in *fpath*.
     If file *fpath* exists, a IOError will be raised."""
     mode = int(mode)
     if not fcheck.mode_check(mode):
         raise ValueError("wrong mode: %r" % oct(mode))
     fd = -1
     try:
         fd = fcntl.open(fpath, fcntl.O_RDONLY | fcntl.O_CREAT, mode)
     finally:
         if fd >= 0:
             unistd.close(fd)
Example #4
0
 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
Example #5
0
 def open(path, create=0, mode=0755):
     """Open a file descriptor for a directory path using read-only mode.
     We keep a copy of the directory path within the object for future
     reference. The object created will keep a file descriptor opened for
     the corresponding directory until close or destructor is called"""
     fd = -1
     path = os.path.abspath(path)
     try:
         fd = fcntl.open(path, unistd.O_DIRECTORY|unistd.O_CREAT if create else 0, mode)
         fd = Directory(fd)
     except:
         if fd > -1:
             os.close(fd)
         raise
     return fd
Example #6
0
 def open(path, create=0, mode=0755):
     """Open a file descriptor for a directory path using read-only mode.
     We keep a copy of the directory path within the object for future
     reference. The object created will keep a file descriptor opened for
     the corresponding directory until close or destructor is called"""
     fd = -1
     path = os.path.abspath(path)
     try:
         fd = fcntl.open(
             path, unistd.O_DIRECTORY | unistd.O_CREAT if create else 0,
             mode)
         fd = Directory(fd)
     except:
         if fd > -1:
             os.close(fd)
         raise
     return fd