def close(self): """ Close the file descriptor """ if self._fd: do_close(self._fd) self._fd = None
def get_etag(path_or_fd): """ FIXME: It would be great to have a translator that returns the md5sum() of the file as an xattr that can be simply fetched. Since we don't have that we should yield after each chunk read and computed so that we don't consume the worker thread. """ etag = '' if isinstance(path_or_fd, int): # We are given a file descriptor, so this is an invocation from the # DiskFile.open() method. fd = path_or_fd dup_fd = do_dup(fd) try: etag = _read_for_etag(dup_fd) do_lseek(fd, 0, os.SEEK_SET) finally: do_close(dup_fd) else: # We are given a path to the object when the DiskDir.list_objects_iter # method invokes us. path = path_or_fd fd = do_open(path, os.O_RDONLY) try: etag = _read_for_etag(fd) finally: do_close(fd) return etag
def close(self): """ Close the open file handle if present. """ if self._fd is not None: fd, self._fd = self._fd, None if fd > -1: do_close(fd)
def test_do_close(self): fd, tmpfile = mkstemp() try: fs.do_close(fd) try: os.write(fd, "test") except OSError: pass else: self.fail("OSError expected") finally: os.remove(tmpfile)
def test_do_close_err_fd(self): fd, tmpfile = mkstemp() try: fs.do_close(fd) try: fs.do_close(fd) except SwiftOnFileSystemOSError: pass else: self.fail("SwiftOnFileSystemOSError expected") finally: os.remove(tmpfile)
def get_etag(path): """ FIXME: It would be great to have a translator that returns the md5sum() of the file as an xattr that can be simply fetched. Since we don't have that we should yield after each chunk read and computed so that we don't consume the worker thread. """ # FIXME: really do need to grab precomputed checksum instead fd = do_open(path, os.O_RDONLY) try: etag = _read_for_etag(fd) finally: do_close(fd) return etag
def _close_fd(self): if self._fd is not None: fd, self._fd = self._fd, None if fd > -1: do_close(fd)