def test_get_filename_from_fd_err(self): result = fs.get_filename_from_fd("blah") self.assertEqual(result, None) result = fs.get_filename_from_fd(-1000) self.assertEqual(result, None) result = fs.get_filename_from_fd("blah", True) self.assertEqual(result, None)
def test_get_filename_from_fd(self): tmpdir = mkdtemp() try: fd, tmpfile = mkstemp(dir=tmpdir) result = fs.get_filename_from_fd(fd) self.assertEqual(tmpfile, result) result = fs.get_filename_from_fd(fd, True) self.assertEqual(tmpfile, result) finally: shutil.rmtree(tmpdir)
def write_metadata(path_or_fd, metadata): """ Helper function to write pickled metadata for a File/Directory. :param path_or_fd: File/Directory path or fd to write the metadata :param metadata: dictionary of metadata write """ assert isinstance(metadata, dict) metastr = pickle.dumps(metadata, PICKLE_PROTOCOL) key = 0 while metastr: try: do_setxattr(path_or_fd, '%s%s' % (METADATA_KEY, key or ''), metastr[:MAX_XATTR_SIZE]) except IOError as err: if err.errno in (errno.ENOSPC, errno.EDQUOT): if isinstance(path_or_fd, int): filename = get_filename_from_fd(path_or_fd) do_log_rl("write_metadata(%d, metadata) failed: %s : %s", path_or_fd, err, filename) else: do_log_rl("write_metadata(%s, metadata) failed: %s", path_or_fd, err) raise DiskFileNoSpace() else: raise GlusterFileSystemIOError( err.errno, 'setxattr("%s", %s, metastr)' % (path_or_fd, key)) metastr = metastr[MAX_XATTR_SIZE:] key += 1
def write_metadata(path_or_fd, metadata): """ Helper function to write serialized metadata for a File/Directory. :param path_or_fd: File/Directory path or fd to write the metadata :param metadata: dictionary of metadata write """ assert isinstance(metadata, dict) metastr = serialize_metadata(metadata) key = 0 while metastr: try: do_setxattr(path_or_fd, '%s%s' % (METADATA_KEY, key or ''), metastr[:MAX_XATTR_SIZE]) except IOError as err: if err.errno in (errno.ENOSPC, errno.EDQUOT): if isinstance(path_or_fd, int): filename = get_filename_from_fd(path_or_fd) do_log_rl("write_metadata(%d, metadata) failed: %s : %s", path_or_fd, err, filename) else: do_log_rl("write_metadata(%s, metadata) failed: %s", path_or_fd, err) raise DiskFileNoSpace() else: raise SwiftOnFileSystemIOError( err.errno, '%s, setxattr("%s", %s, metastr)' % (err.strerror, path_or_fd, key)) metastr = metastr[MAX_XATTR_SIZE:] key += 1